Apple - How to install specific version of python on OS X

For Python in macOS, use pyenv:

brew install pyenv

To install a specific Python version, run:

pyenv install <version>

To select a version:

pyenv local 3.5.0

Note that you must update PATH to override the default Python version:


To list available versions:

pyenv versions

See for more information.

$ brew install python3 is equals follow

$ brew install

So. if you want to install a specific version then, you must check before install.

  • Check the git history of python.rb
  • Find the version you want. Now you can use brew install with the corresponding commit hash:
    • 3.4.3_2: brew install
    • 3.5.2_3: $ brew install
    • 3.6.5_1: brew install

There is also: where you can install using brew install sashkab/python/python34 and brew link python34 --force

Please note that python3.rb was renamed to python.rb at some point. Change the URL if necessary.

I have done this sort of thing in two ways - however both do not coexist with homebrew although I suspect there should be a way similar to the macports one.

General package manager

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 that running it allows you to choose which version of python is run by /opt/bin/python. e,g, to select macports python 2.7 port select --set python python27

Each package manager needs to run as the only package manager otherwise it will be confused with unexpected different versions of libraries and executables on its paths.

From comments the similar homebrew way is given in Short answer seems to be brew switch the equivalent to port_select

Python version managers

The other way is install direct from This will install a python into /usr/local/bin I think this installs a python and python3 executable. The issue with Homebrew is that it assumes that things in /usr/local are installed by it and so brew doctor will report these pythons and libraries as issues and as this question shows also the frameworks in /Library will be problematic.

EDIT 8/2018 *** I would now suggest using conda either miniconda or anaconda. This is another package manager but based and mainly meant for python, it also gives the equivalent of python's virtual environments and pyenv (as per other answer) and so each project can be in a different python and different libraries (Macports only switches python version for all projects)