Mac OSX

How to update Python on macOS

Python is a high-level programming language used by a number of software and applications on macOS. Sometimes one needs to install latest or suitable version of python to use a software. In that case, a Python update is needed on your mac to Python2 or Python3. Furthermore, while updating Python you need to make sure that the older versions are still useable because older apps will continue to use the that particular version of the Python. In case, if you delete or replace older Python then certain apps will stop working.

Check current version of Python

Before you head onto updating Python, find which version of Python you are already using. In that case, open terminal on mac and perform the following command:

  • python — version
Python version check on macOS
How to check Python version on macOS

Do check, if you’ve other versions of python installed, use the following command:

  • python3 –version

It’s worth checking, that the system which we are using for this tutorial has both versions of python installed, python2 (using alias python) as well as python3. We’ll need to update these versions separately to their latest counterparts.

Note: It’s always wise to maintain two versions of Python on your macOS. In most macOS versions, certain terminal apps and other supported software use Python2 with alias set as python.

Update Python on macOS

Now that you know which version of python libraries you are using, all you’ve to find is the latest version. In the above example, Python3 is using version 3.9.1, so let’s update it by using following procedure:

  • Download Python’s latest version from here. Scroll down a bit and find Release version, Release date and select one version later than the already installed one.
  • I’ve selected Python 3.10.2 and on next page, scroll down and find Files and download macOS 64-bit universal2 installer.
  • Once downloaded, double-click and run the installer.
  • Open terminal after the installation and write python3 –version and hit enter. You’ll notice that python3 is updated or installed, as required.

Now, any application or software which needs to use python3 will have to invoke it at path /usr/local/bin/python3 or with alias python3 in terminal. The default python on macOS will rest in /usr/local/bin/python. Similarly, you will have to use pip3 for managing python3 packages.

Conclusion:

If you want to update python then don’t change the default one on macOS instead download a newer one and use it with another terminal alias like python3. Similarly, if you want to use pip (python package manager) and python alias for the latest version then you’ll need to manage it with an amazing application pyenv (a simple Python version management tool) which creates separated environment of execution. Using that application to manage different python versions is beyond the scope of this article at the moment.