virtualenvwrapper 和 Python 3
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16123459/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
virtualenvwrapper and Python 3
提问by damon
I installed python 3.3.1 on ubuntu lucid and successfully created a virtualenv as below
我在 ubuntu lucid 上安装了 python 3.3.1 并成功创建了一个 virtualenv,如下所示
virtualenv envpy331 --python=/usr/local/bin/python3.3
this created a folder envpy331on my home dir.
这envpy331在我的主目录上创建了一个文件夹。
I also have virtualenvwrapperinstalled.But in the docs only 2.4-2.7versions of pythonare supported..Has anyone tried to organize the python3virtualenv ? If so, can you tell me how ?
我也有virtualenvwrapperinstalled.But在文档中唯一2.4-2.7版本python是supported..Has任何人试图组织python3的virtualenv?如果是这样,你能告诉我怎么做吗?
采纳答案by unutbu
The latest version of virtualenvwrapperis tested under Python3.2. Chances are good it will work with Python3.3 too.
该virtualenvwrapper的最新版本是Python3.2下进行测试。很有可能它也适用于 Python3.3。
回答by Ioannis Filippidis
This poston the bitbucket issue tracker of virtualenvwrappermay be of interest. It is mentioned there that most of virtualenvwrapper's functions work with the venvvirtual environments in Python 3.3.
这篇关于virtualenvwrapper的 bitbucket 问题跟踪器的帖子可能会引起关注。那里提到,大多数 virtualenvwrapper 的函数都适用于 Python 3.3 中的venv虚拟环境。
回答by Iliyan Bobev
You can make virtualenvwrapper use a custom Python binary instead of the one virtualenvwrapper is run with. To do that you need to use VIRTUALENV_PYTHON variable which is utilized by virtualenv:
您可以让 virtualenvwrapper 使用自定义 Python 二进制文件,而不是运行 virtualenvwrapper 的一个。为此,您需要使用 virtualenv 使用的 VIRTUALENV_PYTHON 变量:
$ export VIRTUALENV_PYTHON=/usr/bin/python3
$ mkvirtualenv -a myproject myenv
Running virtualenv with interpreter /usr/bin/python3
New python executable in myenv/bin/python3
Also creating executable in myenv/bin/python
(myenv)$ python
Python 3.2.3 (default, Oct 19 2012, 19:53:16)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
回答by Jonathan
If you already have python3 installed as well virtualenvwrapper the only thing you would need to do to use python3 with the virtual environment is creating an environment using:
如果您已经安装了 python3 以及 virtualenvwrapper,那么在虚拟环境中使用 python3 唯一需要做的就是使用以下方法创建一个环境:
which python3 #Output: /usr/bin/python3
mkvirtualenv --python=/usr/bin/python3 nameOfEnvironment
Or, (at least on OSX using brew):
或者,(至少在 OSX 上使用 brew):
mkvirtualenv --python=`which python3` nameOfEnvironment
Start using the environment and you'll see that as soon as you type python you'll start using python3
开始使用环境,你会看到只要你输入 python 你就会开始使用 python3
回答by CuriousGeorge
I find that running
我发现跑步
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
and
和
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/bin/virtualenv-3.4
in the command line on Ubuntu forces mkvirtualenv to use python3 and virtualenv-3.4. One still has to do
在 Ubuntu 的命令行中强制 mkvirtualenv 使用 python3 和 virtualenv-3.4。一个还得做
mkvirtualenv --python=/usr/bin/python3 nameOfEnvironment
to create the environment. This is assuming that you have python3 in /usr/bin/python3 and virtualenv-3.4 in /usr/local/bin/virtualenv-3.4.
创造环境。这是假设您在 /usr/bin/python3 中有 python3,在 /usr/local/bin/virtualenv-3.4 中有 virtualenv-3.4。
回答by Peter Yin
virtualenvwrapper now lets you specify the python executable without the path.
virtualenvwrapper 现在允许您指定没有路径的 python 可执行文件。
So (on OSX at least)mkvirtualenv --python=python3 nameOfEnvironmentwill suffice.
所以(至少在 OSX 上)mkvirtualenv --python=python3 nameOfEnvironment就足够了。
回答by akashbw
On Ubuntu; using mkvirtualenv -p python3 env_nameloads the virtualenv with python3.
在 Ubuntu 上;using 使用mkvirtualenv -p python3 env_namepython3 加载 virtualenv。
Inside the env, use python --versionto verify.
在 env 中,用于python --version验证。
回答by chorbs
You can add this to your .bash_profile or similar:
您可以将其添加到您的 .bash_profile 或类似文件中:
alias mkvirtualenv3='mkvirtualenv --python=`which python3`'
Then use mkvirtualenv3instead of mkvirtualenvwhen you want to create a python 3 environment.
然后在要创建 python 3 环境时使用mkvirtualenv3而不是mkvirtualenv。
回答by Mustapha-Belkacim
I added export VIRTUALENV_PYTHON=/usr/bin/python3to my ~/.bashrclike this:
export VIRTUALENV_PYTHON=/usr/bin/python3我~/.bashrc像这样添加到我的:
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENV_PYTHON=/usr/bin/python3
source /usr/local/bin/virtualenvwrapper.sh
then run source .bashrc
然后运行 source .bashrc
and you can specify the python version for each new env mkvirtualenv --python=python2 env_name
您可以为每个新环境指定 python 版本 mkvirtualenv --python=python2 env_name

