Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I install multiple versions of Python on latest OS X and use them in parallel?

I want to run tests with multiple Python versions on OS X 10.11, including:

  • Python 2.6 - ?!
  • Python 2.7 - default - solved
  • Python 3.4 - ?!
  • Python 3.5 - installed via brew - works well
  • Conda Python 3.5 - ?!

I want to run the tests via tox so tox needs to be able to find them. Sadly it seems that brew doesn't want to install 3.4 since they added 3.5 and I obviously do not want to remove 3.5 one.

like image 798
sorin Avatar asked May 01 '16 15:05

sorin


People also ask

Can I have multiple versions of Python installed on Mac?

In those situations, the Python Version Manager(pyenv) is a great tool to use, allowing you to install multiple versions of Python and switch between them as you see fit.

Can I have multiple versions of Python installed?

If you wish to use multiple versions of Python on a single machine, then pyenv is a commonly used tool to install and switch between versions. This is not to be confused with the previously mentioned depreciated pyvenv script. It does not come bundled with Python and must be installed separately.

Can I have Python 2 and 3 installed at the same time Mac?

You can have both versions installed at the same time.

How do I install both versions of Python?

Install that version using "make install". Install all other versions using "make altinstall". For example, if you want to install Python 2.5, 2.6 and 3.0 with 2.6 being the primary version, you would execute "make install" in your 2.6 build directory and "make altinstall" in the others.


1 Answers

pyenv is the thing you want. It works very very well:

pyenv lets you easily switch between multiple versions of Python. It's simple, unobtrusive, and follows the UNIX tradition of single-purpose tools that do one thing well. This project was forked from rbenv and ruby-build, and modified for Python.

https://github.com/pyenv/pyenv

Install it via Homebrew:

$ brew update $ brew install pyenv 

It handles the download, compilation, and installation of various pythons for you, e.g.:

$ pyenv install 3.7.2 

It can show you which versions you've installed, and which is active:

$ pyenv versions   system   3.6.7 * 3.7.2 

When you're in a new project directory, just tell pyenv which python version to use there:

$ pyenv local 3.6.7  # Because e.g. tensorflow isn't compat. with 3.7 :-( 

You can set a 'default' version everywhere else:

$ pyenv global 3.7.2 
like image 102
Dogweather Avatar answered Oct 19 '22 05:10

Dogweather