简体   繁体   English

使用python2和python3创建virtualenv

[英]Create a virtualenv with both python2 and python3

I tried to use virtualenvwrapper to create a virtualenv with both python2 and python3 我尝试使用virtualenvwrapper创建一个兼具python2和python3的virtualenv

Per virtualenv with python2 and python3 via Homebrew I hoped this would work: 每个virtualenv与python2和python3通过Homebrew我希望这将工作:

(The name of the virtualenv is 'double') (virtualenv的名字是'double')

mkvirtualenv double -p `which python`
mkvirtualenv double -p `which python3`

It mentions that 它提到了这一点

Not overwriting existing python script both/bin/python (you must use both/bin/python3.4)

But it that does not seem to be true. 但这似乎并非如此。 Typing python python2.7 python3 and python3.4 all start the python3.4 interpreter. 键入python python2.7 python3python3.4都会启动python3.4解释器。

Sorry, virtualenv is designed to support single interpreter version. 抱歉,virtualenv旨在支持单一解释器版本。

If you need to use several python versions on the same codebase please create separate virtual environments. 如果您需要在同一代码库上使用多个python版本,请创建单独的虚拟环境。

virtualenv does not support multiple interpreter versions . virtualenv不支持多个解释器版本。 My suggestion is to use different environment for each of the versions : 我的建议是为每个版本使用不同的环境:

virtualenv -p /usr/bin/python3.3 py3env
virtualenv -p /usr/bin/python py2env

virtualenv help you to isolate environments. virtualenv帮助您隔离环境。

It can't support multiple python version in the same time. 它不能同时支持多个python版本。 You can try pyenv and pyenv-virtualenv . 你可以尝试pyenvpyenv-virtualenv It support you change folder to another python version and work environment. 它支持您将文件夹更改为另一个python版本和工作环境。 It switch version very easily. 它很容易切换版本。

If you can't install pyenv and work on Mac. 如果你不能安装pyenv并在Mac上工作。 anyenv can help you to install pyenv . anyenv可以帮你安装pyenv

Example: 例:

$ pyenv install 3.4.1
$ pyenv install 2.7.6
$ pyenv virtualenv 3.4.1 mypy3
$ pyenv virtualenv 2.7.6 mypy2
$ pyenv versions
  * system
    3.4.1
    2.7.6
    mypy3

$ cd /work/
$ pyenv local mypy3      # Use Py3 now
$ pyenv local mypy2      # Use Py2 now 
virtualenv -p /path/to/your/python/version/exectuable ENV

is what you want . 你想要的 (I know that this is an old question, but I looked here now, and found that the answers aren't updated). (我知道这是一个老问题,但我现在看了一下,发现答案没有更新)。

I have a solution for this involving Vagrant/VirtualBox... (it has my bootstrap setup for starting a django probject, but fork it and go wild with it!) 我有一个解决方案,涉及Vagrant / VirtualBox ...(它有我的引导程序设置,用于启动一个django项目,但是把它分叉并随之疯狂!)

the package is here, https://github.com/andrewyoung1991/python-3.4.1-vagrant-bootstrap.git a virtual-env is unfortunately a single-python game but with a VirtualBox you can work freely in a sandbox calling python2 or python3 这个软件包在这里, https://github.com/andrewyoung1991/python-3.4.1-vagrant-bootstrap.git虚拟env很遗憾是一个单人python游戏,但有一个VirtualBox,你可以在沙盒中自由工作,调用python2或python3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM