How can I install multiple versions of Python on latest OS X and use them in parallel?
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
This blog post suggests using pyenv
with the desired detox
. The basic setup with brew
requires:
brew install pyenv pyenv-virtualenv pyenv-virtualenvwrapper
Then installing the desired Python versions with pyenv install [version]
, rather than installing Python using brew
. You can check the available versions using pyenv versions
.
Finally, pip install detox
will ensure you've got tox
and detox
installed. Then you should be able to specify the desired testing versions in your tox.ini
.
brew
alone has been sufficient for me to use multiple versions of Python. I haven't needed pyenv
or conda
for it.
To install various versions using brew
, run commands such as:
brew install [email protected]
brew install [email protected]
When creating a virtual environment, create it using one of:
/usr/local/opt/[email protected]/bin
/usr/local/opt/[email protected]/bin
I would avoid using /usr/local/bin/python3
when creating a virtual environment because the version that it points to can change.
As previous answers also mentioned.. no pyenv needed, this works perfect for me:
brew install [email protected]
brew install [email protected]
brew install [email protected]
Then just add the corresponding version lines to the ~/.bashrc
export PATH="$PATH:/usr/local/opt/[email protected]/Frameworks/Python.framework/Versions/3.7/bin"
export PATH="$PATH:/usr/local/opt/[email protected]/Frameworks/Python.framework/Versions/3.8/bin"
export PATH="$PATH:/usr/local/opt/[email protected]/Frameworks/Python.framework/Versions/3.9/bin"