I would recommend ignoring the other link here to stackoverflow. It popularizes the installation of Python 3 via home brew and that is a mess. What I have done, and one that requires zero dinking around after the installation is to install the 64-bit Python 3.7.3 from Python dot org. Do not install the 32-bit/64-bit version that is also available from there.
- Nothing to compile via a package manager, and does not interfere with Apple Python implementation.
- Proper installer places the framework build of Python 3.7.3 into /Library/Frameworks, and links the binaries (e.g. python3, idle3, pip3) back into /usr/local/bin with those names.
WIth the above package installed, you would invoke Python 3.7.3 with the command-line python3. It will automatically know where its library modules are located without any additional symlink nonsense that a package manager causes. Don't overlook using the interactive idle3 for development work either.
If you want to run Python 3 in a Python script, the first and second lines of the script should be:
#!/usr/bin/env python3
# coding: utf-8
and to run Python 2.7.10:
#!/usr/bin/env python
# coding: utf-8
and to run a Python script without these initial lines:
python tkver.py
python3 tkver.py
tkver.py:
import sys
try:
import Tkinter as tk # Python 2
except ImportError:
import tkinter as tk # Python 3
print("Tcl Version: {}".format(tk.Tcl().eval('info patchlevel')))
print("Tk Version: {}".format(tk.Tk().eval('info patchlevel')))
sys.exit()
This code will report the versions of Tcl/Tk used by Apple's Python 2.7.10, and bundled with Python.org's Python 3.7.3.