Installing Python 3 on macOS
Practical Guide
1 Getting Started
By default, macOS comes with Python 2 pre-installed for compatibility, accessible at /usr/bin/python.
If you install Xcode, Apple’s development environment, Python 3 is also included, typically at /usr/bin/python3. You can check the installed version by running python3 in the terminal. If it’s up-to-date, you may already have everything you need.
For modern Python development, we will be using Python 3.
One limitation is that the version provided by Apple is tied to Xcode updates, so you don’t have much control over which Python 3 version you get. For example, I had Python 3.8 installed, even though Python 3.9 was available.
To get the latest version of Python, you have a few options. One is using Homebrew to install it. Another is to download the official Python package directly, which is the method we’ll follow here.
Visit https://www.python.org, open the Downloads menu, hover over “Mac OS X,” and a link to download the official installer will appear.
Click that, and run the installer:
Click “Continue”:
Next, click “Continue” once more. A new screen will appear, providing a brief overview of Python’s history and its governance.
In 1995, Guido continued his work on Python at the Corporation for National Research Initiatives (CNRI, see http://www.cnri.reston.va.us) in Reston, Virginia where he released several versions of the software.
In May 2000, Guido and the Python core development team moved to BeOpen.com to form the BeOpen PythonLabs team. In October of the same year, the PythonLabs team moved to Digital Creations (now Zope Corporation, see http://www.zope.org). In 2001, the Python Software Foundation (PSF, see http://www.python.org/psf/) was formed, a non-profit organization created specifically to own Python-related Intellectual Property. Zope Corporation is a sponsoring member of the PSF.
Next, you’ll see the Python license. Python is open source and distributed under the Python Software Foundation License Version 2.
This license is compatible with the GPL, meaning Python can be used alongside GPL-licensed software. However, Python itself is not GPL. Unlike GPL, which requires any derivative software to also be released under GPL and its source code made available, Python’s license does not impose these restrictions. You’re free to release your Python programs’ source code, but it’s entirely optional.
Click Agree to accept the license and continue:
Then move to the installation phase:
Once the installation is complete, Python will be available at usr/bin/python3.
Running python3 in the macOS terminal will now launch the Python 3.9 interpreter we just installed.
After installation, you’ll notice a new folder in /Applications named something like Python 3.9 (the version number may differ depending on what you installed). This folder contains several supporting files and tools for Python.
As noted in the final installation panel, you need to run “Install Certificates.command” to set up the SSL certificates that Python requires.
Simply double-click Install Certificates.command, and it will complete the setup quickly:
The folder also includes IDLE, a standalone application that opens the Python interpreter in its own window, providing a simple environment for writing and testing Python code.
The folder also provides a link to the official Python documentation, the license, and Python Launcher, a utility that helps you manage multiple Python versions on your system and allows you to specify which version should run a given script.
Be careful not to confuse the python command, which still points to the older Python 2 version. Using it by mistake can cause issues.
A good practice is to create a shell alias so that running python automatically executes python3.
For example, in the Fish shell, you can set this up by running:
alias python "python3"
alias pip "pip3"
funcsave python
funcsave pipYou can enter this directly in the terminal.
Additionally, ensure that the pip binaries are included in your shell’s PATH so that you can run them from anywhere without issues.
set PATH ~/Library/Python/3.9/bin $PATH(Replace 3.9 with the version you installed)
If you’re using Zsh, add the alias to your ~/.zshrc file in your home directory:
alias python="python3"
If you’re using Bash, add the alias to your ~/.bashrc file in your home directory:
alias python="python3"After setting up the alias, running python in the terminal will now launch the Python 3 version you just installed.
A convenient way to use pip, Python’s package manager, is to run it through Python directly using:
python -m pip <COMMAND>instead of calling pip <COMMAND> directly. For example:
python -m pip install djangoIt’s recommended to always use a virtual environment with venv when installing or managing Python packages, to keep your projects isolated and avoid conflicts.