When I reinstalled my iMac with macOS Catalina in January 2020 I stubbled upon a error that I had seen before but I convenience ignored every time it popped-up. The first time I read it I thought I will fix it when I need to. But now I can’t ignore it anymore. the message I saw in my terminal was:
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support.
Time to take a deeper look at this upgrade of Pyton to Python 3 and how to solve the problems that come with it.
Historically MacOS came preinstalled with Python 2, however starting with macOS Catalina 10.15 (released in October 2019) this is no longer the case. And since Python 2 will no longer be officially supported as of January 1, 2020, you should really use Python 3 instead.
There are multiple ways to install Python 3 on a MacOS computer. The official Python website even recommends downloading it directly, however this approach can cause confusion around PATH variables, updates, and uninstalls. A better approach, in my opinion, is to instead use the popular package manager Homebrew which automates updates and juggling multiple versions of Python on a computer.
Check Python version
Before we start, make sure Python 3 isn’t already installed on your computer. Open the Terminal app. Click the Finder icon in your dock. Click Go. Click Utilities. Double-click Terminal.
Then type the command
followed by the Enter key to see the currently installed version of Python.
% python --version Python 2.7.16
Note: The percent sign, (%), indicates user input. Everything after is intended to be typed by the user followed by the Enter key. Any output, such as Python 2.7.17 in this case, does not have a dollar sign in front. In short: don’t type % before your commands!
It’s possible that Python 3 may have already been installed as python3. Run the command
to check, however most likely this will throw an error.
The first step for Python 3 is to install Apple’s Xcode program which is necessary for iOS development as well as most programming tasks. We will use XCode to install Homebrew.
In your Terminal app, run the following command to install XCode and its command-line tools:
% xcode-select --install
It is a large program so this make take a while to download. Make sure to click through all the confirmation prompts XCode requires.
Next install Homebrew by copy/pasting the following command into Terminal and then type Enter:
% ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
To confirm Homebrew installed correctly, run this command:
% brew doctor Your system is ready to brew.
Install Python 3
Now we can install the latest version of Python 3. Type the following command into Terminal and press Enter:
% brew install python3
To confirm which version of Python 3 was installed, run the following command in Terminal:
% python3 --version Python 3.7.6
Finally, to run our new version of Python 3 open an interactive shall by typing python3 within Terminal:
% python3 Python 3.7.6 (default, Dec 30 2019, 19:38:26) [Clang 11.0.0 (clang-1220.127.116.11)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>>
To exit the Python 3 interactive shell, you can type either exit() and then Return or type Control+d which means hold both the Control and D keys at the same time.
Note: It is still possible to run Python 2 by simply typing python:
% python WARNING: Python 2.7 is not recommended. This version is included in macOS for compatibility with legacy software. Future versions of macOS will not include Python 2.7. Instead, it is recommended that you transition to using 'python3' from within Terminal. Python 2.7.16 (default, Nov 9 2019, 05:55:08) [GCC 4.2.1 Compatible Apple LLVM 11.0.0 (clang-118.104.22.168) (-macos10.15-objc-s on darwin Type "help", "copyright", "credits" or "license" for more information. >>>
DO YOU HAVE ANY QUESTIONS? LEAVE A COMMENT DOWN HERE.