Instantly share code, notes, and snippets.

Embed
What would you like to do?
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.

@tmehlinger

This comment has been minimized.

Show comment
Hide comment
@tmehlinger

tmehlinger Dec 18, 2014

The Python 3.2 install will fail on newer versions of Homebrew because the formula is incompatible. I had to comment out lines 133-141 of Library/Formula/python3.rb and install Setuptools and Pip manually after the Python install finished.

Other than that, worked perfectly, thanks for taking the time to document this. :)

tmehlinger commented Dec 18, 2014

The Python 3.2 install will fail on newer versions of Homebrew because the formula is incompatible. I had to comment out lines 133-141 of Library/Formula/python3.rb and install Setuptools and Pip manually after the Python install finished.

Other than that, worked perfectly, thanks for taking the time to document this. :)

@IvanExpert

This comment has been minimized.

Show comment
Hide comment
@IvanExpert

IvanExpert Apr 5, 2015

Thanks for this writeup -- very helpful. Also thanks tmhlinger for your tip.

IvanExpert commented Apr 5, 2015

Thanks for this writeup -- very helpful. Also thanks tmhlinger for your tip.

@Bouke

This comment has been minimized.

Show comment
Hide comment
@Bouke

Bouke Apr 7, 2015

The brew versions command has been removed. The instructions are no longer valid.

Owner

Bouke commented Apr 7, 2015

The brew versions command has been removed. The instructions are no longer valid.

@zoidbergwill

This comment has been minimized.

Show comment
Hide comment
@zoidbergwill

zoidbergwill Apr 30, 2015

This worked perfectly for me, I just skipped the brew versions line.

zoidbergwill commented Apr 30, 2015

This worked perfectly for me, I just skipped the brew versions line.

@tdsmith

This comment has been minimized.

Show comment
Hide comment
@tdsmith

tdsmith Sep 14, 2015

I'm a Homebrew maintainer; I strongly suggest you use pyenv instead if you ever need anything but the most current Python versions. It's a much nicer solution in part because it's designed to handle switching scripts back and forth, which is very difficult for Homebrew to do.

tdsmith commented Sep 14, 2015

I'm a Homebrew maintainer; I strongly suggest you use pyenv instead if you ever need anything but the most current Python versions. It's a much nicer solution in part because it's designed to handle switching scripts back and forth, which is very difficult for Homebrew to do.

@Bouke

This comment has been minimized.

Show comment
Hide comment
@Bouke

Bouke Sep 18, 2015

Thanks, I didn't know about pyenv, but found very useful already. I've updated the document as this looks like a better way to do this.

Owner

Bouke commented Sep 18, 2015

Thanks, I didn't know about pyenv, but found very useful already. I've updated the document as this looks like a better way to do this.

@denfromufa

This comment has been minimized.

Show comment
Hide comment
@denfromufa

denfromufa Sep 28, 2016

The link is broken:

Using tox and pyenv for testing and development
http://tbb.co/using-tox-and-pyenv-for-testing-and-development/

denfromufa commented Sep 28, 2016

The link is broken:

Using tox and pyenv for testing and development
http://tbb.co/using-tox-and-pyenv-for-testing-and-development/

@denfromufa

This comment has been minimized.

Show comment
Hide comment
@denfromufa

denfromufa commented Sep 28, 2016

I believe the new link is now here:

http://www.holger-peters.de/using-pyenv-and-tox.html

@Bouke

This comment has been minimized.

Show comment
Hide comment
@Bouke

Bouke Sep 28, 2016

Thanks @denfromufa, I've updated the link.

Owner

Bouke commented Sep 28, 2016

Thanks @denfromufa, I've updated the link.

@matinfo

This comment has been minimized.

Show comment
Hide comment
@matinfo

matinfo Mar 20, 2017

Good to know, to not use default Python of OSX Sierra:

Add to your shell (~/.bashrc or ~/.zshrc) :

export PATH="/Users/username/.pyenv:$PATH"
eval "$(pyenv init -)"

Remplace username by your MacBook user.
Refresh your terminal env, example: $ source ~/.zshrc (or restart your terminal)

matinfo commented Mar 20, 2017

Good to know, to not use default Python of OSX Sierra:

Add to your shell (~/.bashrc or ~/.zshrc) :

export PATH="/Users/username/.pyenv:$PATH"
eval "$(pyenv init -)"

Remplace username by your MacBook user.
Refresh your terminal env, example: $ source ~/.zshrc (or restart your terminal)

@yanpeng

This comment has been minimized.

Show comment
Hide comment
@yanpeng

yanpeng Jun 8, 2017

@matinfo it saves me :-)

yanpeng commented Jun 8, 2017

@matinfo it saves me :-)

@devhero

This comment has been minimized.

Show comment
Hide comment
@devhero

devhero Jun 12, 2017

@matinfo

Can also works using shims (pyenv doc):

export PATH="/shims:$PATH"
eval "$(pyenv init -)"

devhero commented Jun 12, 2017

@matinfo

Can also works using shims (pyenv doc):

export PATH="/shims:$PATH"
eval "$(pyenv init -)"

@gino8080

This comment has been minimized.

Show comment
Hide comment
@gino8080

gino8080 Dec 3, 2017

great thankyou!

gino8080 commented Dec 3, 2017

great thankyou!

@Yammmy

This comment has been minimized.

Show comment
Hide comment
@Yammmy

Yammmy Mar 3, 2018

Nice work~

Yammmy commented Mar 3, 2018

Nice work~

@nachozt

This comment has been minimized.

Show comment
Hide comment
@nachozt

nachozt Mar 8, 2018

Thanks!!

nachozt commented Mar 8, 2018

Thanks!!

@adlersantos

This comment has been minimized.

Show comment
Hide comment
@adlersantos

adlersantos Jun 5, 2018

Thank you guys!

adlersantos commented Jun 5, 2018

Thank you guys!

@danishbacker

This comment has been minimized.

Show comment
Hide comment
@danishbacker

danishbacker Aug 20, 2018

Thank you 👍

danishbacker commented Aug 20, 2018

Thank you 👍

@cindyloo

This comment has been minimized.

Show comment
Hide comment
@cindyloo

cindyloo Aug 27, 2018

yes, very helpful!

cindyloo commented Aug 27, 2018

yes, very helpful!

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