问题:virtualenvwrapper和Python 3

我在ubuntu lucid上安装了python 3.3.1并成功创建了virtualenv,如下所示

virtualenv envpy331 --python=/usr/local/bin/python3.3

envpy331在我的主目录上创建了一个文件夹。

我也已经virtualenvwrapper安装了。但是在文档中仅支持的2.4-2.7版本。python是否有人试图组织python3virtualenv?如果是这样,您能告诉我如何吗?

I installed python 3.3.1 on ubuntu lucid and successfully created a virtualenv as below

virtualenv envpy331 --python=/usr/local/bin/python3.3

this created a folder envpy331 on my home dir.

I also have virtualenvwrapper installed.But in the docs only 2.4-2.7 versions of python are supported..Has anyone tried to organize the python3 virtualenv ? If so, can you tell me how ?


回答 0

virtualenvwrapper的最新版本是Python3.2下进行测试。很有可能它也可以与Python3.3一起使用。

The latest version of virtualenvwrapper is tested under Python3.2. Chances are good it will work with Python3.3 too.


回答 1

如果您已经安装了python3以及virtualenvwrapper,那么在虚拟环境中使用python3的唯一操作就是使用以下命令创建环境:

which python3 #Output: /usr/bin/python3
mkvirtualenv --python=/usr/bin/python3 nameOfEnvironment

或者,(至少在使用brew的OSX上):

mkvirtualenv --python=`which python3` nameOfEnvironment

开始使用环境,您将看到在键入python后立即开始使用python3

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:

which python3 #Output: /usr/bin/python3
mkvirtualenv --python=/usr/bin/python3 nameOfEnvironment

Or, (at least on OSX using 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


回答 2

您可以使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.

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:

$ 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.

回答 3

virtualenvwrapper现在允许您指定不带路径的python可执行文件。

因此(至少在OSX上)mkvirtualenv --python=python3 nameOfEnvironment就足够了。

virtualenvwrapper now lets you specify the python executable without the path.

So (on OSX at least)mkvirtualenv --python=python3 nameOfEnvironment will suffice.


回答 4

在Ubuntu上;使用使用mkvirtualenv -p python3 env_namepython3加载virtualenv。

在环境内部,用于python --version验证。

On Ubuntu; using mkvirtualenv -p python3 env_name loads the virtualenv with python3.

Inside the env, use python --version to verify.


回答 5

您可以将其添加到您的.bash_profile或类似文件中:

alias mkvirtualenv3='mkvirtualenv --python=`which python3`'

然后在要创建python 3环境时使用mkvirtualenv3代替mkvirtualenv

You can add this to your .bash_profile or similar:

alias mkvirtualenv3='mkvirtualenv --python=`which python3`'

Then use mkvirtualenv3 instead of mkvirtualenv when you want to create a python 3 environment.


回答 6

我发现跑步

export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3

export VIRTUALENVWRAPPER_VIRTUALENV=/usr/bin/virtualenv-3.4

在Ubuntu上的命令行中,强制mkvirtualenv使用python3和virtualenv-3.4。仍然要做

mkvirtualenv --python=/usr/bin/python3 nameOfEnvironment

创造环境。假设您在/ usr / bin / python3中有python3,在/usr/local/bin/virtualenv-3.4中有virtualenv-3.4。

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

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.


回答 7

关于virtualenvwrapper的bitbucket问题跟踪器的这篇文章可能很有趣。在那里提到,大多数virtualenvwrapper的功能都可以在Python 3.3中的venv虚拟环境中使用。

This post on the bitbucket issue tracker of virtualenvwrapper may be of interest. It is mentioned there that most of virtualenvwrapper’s functions work with the venv virtual environments in Python 3.3.


回答 8

我这样添加export VIRTUALENV_PYTHON=/usr/bin/python3到我的~/.bashrc

export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENV_PYTHON=/usr/bin/python3
source /usr/local/bin/virtualenvwrapper.sh

然后跑 source .bashrc

您可以为每个新环境指定python版本 mkvirtualenv --python=python2 env_name

I added export VIRTUALENV_PYTHON=/usr/bin/python3 to my ~/.bashrc like this:

export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENV_PYTHON=/usr/bin/python3
source /usr/local/bin/virtualenvwrapper.sh

then run source .bashrc

and you can specify the python version for each new env mkvirtualenv --python=python2 env_name


声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。