问题
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.
回答1:
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.
回答2:
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
回答3:
I'd highly recommend using a package manager such as Anaconda, https://www.continuum.io/downloads, which it makes it trivially easy to install different self-contained virtual-envs.
For example, to create a virtual environment with numpy and Python 2.7 this is the command:
conda create --name py2_env numpy python=2.7
And then to switch to that environment:
source activate py2_env
回答4:
pyenv is all well and good but I feel that we should give a mention to the wonderful pipenv library from Kenneth Reitz.
https://github.com/pypa/pipenv
It provides the functionality of pyenv plus dependency locking, support for .env out-of-the-box and much more.
来源:https://stackoverflow.com/questions/36968425/how-can-i-install-multiple-versions-of-python-on-latest-os-x-and-use-them-in-par