Can I update python version on my MacBook's Terminal?

My current Mac is running Python2 on Terminal. I'd like to use Python3 on Terminal.

Last login: Tue Apr 16 17:37:14 on ttys000


haithams-mbp-2:Desktop haithammogherbi$ python --version


Python 2.7.10


can I update to python3? or will this cause an issue for other apps using python2?

MacBook Pro 13", macOS 10.14

Posted on Apr 17, 2019 4:08 AM

Reply
Question marked as Top-ranking reply

Posted on Apr 29, 2019 3:32 AM

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.


  1. Nothing to compile via a package manager, and does not interfere with Apple Python implementation.
  2. 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.

5 replies
Question marked as Top-ranking reply

Apr 29, 2019 3:32 AM in response to HaithamMogherbi

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.


  1. Nothing to compile via a package manager, and does not interfere with Apple Python implementation.
  2. 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.

Apr 29, 2019 5:09 AM in response to Luis Sequeira1

Over the years, I have seen users post here that they have some unexplained problem in the Anaconda distribution and there is either no response, or slow response because the average Mac user is not running, and unfamiliar with this superset of the standard distribution aimed at the science community. It is a personal preference thing — just not mine.


I run pristine Python 3 from Python dot org. No surprises, and only the packages that I choose to install — not extra baggage that I do not need or will ever use. The pip3 installer in Python 3 is there if I choose to add optional packages. My Sublime Text 3 programmer's editor is running the Anaconda Python IDE package, not the Anaconda Python distribution.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Can I update python version on my MacBook's Terminal?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.