Skip to content

Instantly share code, notes, and snippets.

@Bouke
Last active August 3, 2023 01:46
Show Gist options
  • Save Bouke/11261620 to your computer and use it in GitHub Desktop.
Save Bouke/11261620 to your computer and use it in GitHub Desktop.
Multiple Python installations on OS X

Previous versions used homebrew to install the various versions. As suggested in the comments, it's better to use pyenv instead. If you are looking for the previous version of this document, see the revision history.

$ brew update
$ brew install pyenv
$ pyenv install 3.5.0
$ pyenv install 3.4.3
$ pyenv install 3.3.6
$ pyenv install 3.2.6
$ pyenv install 2.7.10
$ pyenv install 2.6.9
$ pyenv versions
* system (set by /Users/bouke/.pyenv/version)
  2.6.9
  2.7.10
  3.2.6
  3.3.6
  3.4.3
  3.5.0

Then, when you need a certain version:

pyenv local 3.5.0

This will create a file .python-version, so pyenv will remember the Python version for this directory. This works also nice with tox, as you can activate many Python version at once. See the pyenv documentation for more information.

See also Using tox and pyenv for testing and development for a more detailed how-to.

@LongBu
Copy link

LongBu commented Feb 20, 2019

@crapthings

Try the following:

CFLAGS="-I$(brew --prefix readline)/include -I$(brew --prefix openssl)/include -I$(xcrun --show-sdk-path)/usr/include" LDFLAGS="-L$(brew --prefix readline)/lib -L$(brew --prefix openssl)/lib" PYTHON_CONFIGURE_OPTS=--enable-unicode=ucs2 pyenv install -v 3.7.2

reference:
pyenv/pyenv#1219

@easyas314
Copy link

Yikes! I had the same error as @crapthings and the arcane incantation from @LongBu made my screen puke all fun kinds of output and eventually ended with:

Collecting setuptools
Collecting pip
Installing collected packages: setuptools, pip
Successfully installed pip-18.1 setuptools-40.6.2
/var/folders/rz/fjd3x9jn24n8kxhybt17yh_40000gn/T/python-build.20190224164731.13157 ~
~
Installed Python-3.7.2 to /Volumes/DATA_MAC/brad/.pyenv/versions/3.7.2

... and pyenv versions lists 3.7.2
Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment