Installing Python 3.7 on OSX

Posted on Oct 17, 2018

Getting python 3.7 installed on OSX might seem simple, but a quick Google search will show you that it’s anything but.

If you don’t follow the steps, you will encounter multiple issues with the way the system is wired. I thought I am going to write a short tutorial type post on how to get it done.

First, we will install pyenv

brew install pyenv

Once we have pyenv install, we can try to install python 3.7 using it

pyenv install 3.7.0
pyenv global 3.7.0

If this fails due to a package missing on your system like zlib or any other system package, you will need to run the ever-wonderful and obscure xcode-select --install

On Mojave, this didn’t work fully and you also need to run

sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /

Once this finished, you can run the following again.

pyenv install 3.7.0
pyenv global 3.7.0

Now, you need to install virtualenvwrapper

PIP_REQUIRE_VIRTUALENV="false" $(pyenv which python3.7) -m pip install virtualenvwrapper

You are almost done, all you need now is to add the following lines to your ~/.bash_profile or ~/.zshrc (depends on which shell you are using)

eval "$(pyenv init -)"
export WORKON_HOME=~/.venvs
export VIRTUALENVWRAPPER_PYTHON=$(pyenv which python3.7)
export VIRTUALENVWRAPPER_VIRTUALENV=$(dirname $(pyenv which python3.7))/virtualenv
source $(dirname $(pyenv which python3.7))/

When you open a new shell and run which python it should point to the shims directory:

› which python

python --version should come up with python 3.7.0.

That’s it. Hope you enjoy and succeed.

Note: Credit to Moshe for writing the original version of this on the Globality internal engineering Wiki.