Sometimes, you might need to use a Python package that requires a specific version of Python. For instance, you want to use a Python package that requires a specific version of Python.
There are a bunch of ways to do this.
How to Install Multiple Specific Versions of Python Using MacPorts
The first is using Macports as the package manager.
There are separate ports for several python versions 2.x and 3.x currently 2.4, 2.5, 2.6, 2.7 and 3.1, 3.2, 3.3 3.4 and 3.5.
For example, to install 3.4, do
sudo port install python34
There is also a python_select port. Running it allows you to choose the Python version to run by /opt/bin/python.
E.g., to select MacPorts python 2.7
port select --set python python27
Note: each package manager needs to run as the only package manager. Otherwise, it will be confused with different versions of libraries and executables on its paths.
With homebrew, the short answer seems to be
brew switch the equivalent to port_select.
How to Install Multiple Specific Versions of Python Using Pyenv
Install pyenv using homebrew
brew install pyenv
Install the specific Python version, run:
pyenv install <version>
Install specific Python.
Select a python version:
pyenv local 3.5.0
Select a python version.
Note that you must update
PATH to override the default Python version:
To list available versions:
You may have seen suggestions to use package managers like brew_python, pyenv, anaconda, or miniconda.
However, what if you want to install multiple Python versions with a symbolic link on MacOSX without a python package manager?
How to Install Multiple Specific Versions of Python Without a Package Manager
You can install this easily using homebrew on a MacOSX terminal.
Install the required version:
% brew install firstname.lastname@example.org % brew list | grep python % brew ls email@example.com % ls -l /usr/local/Cellarfirstname.lastname@example.org/3.9.10/bin/python3.9
Install the required version.
Add a soft link to /usr/local/bin/
% ln -s /usr/local/Cellaremail@example.com/3.9.10/bin/python3.9 /usr/local/bin/python3.9 % python3.9 -V
Add a soft link.
Create a Python virtual environment
% python3.9 -m venv venv
Create a Python virtual environment.
Activate the virtual environment
% source venv/bin/activate
Activate the virtual environment.
Deactivate the virtual environment
Deactivate the virtual environment.
And that’s it! Hack away.