简体   繁体   English

virtualenvwrapper 和 Python 3

[英]virtualenvwrapper and Python 3

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 envpy331 on my home dir.这在我的主目录上创建了一个文件夹envpy331

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 ?我也安装了virtualenvwrapper 。但是在文档中只支持2.4-2.7版本的python 2.4-2.7有没有人尝试组织python3 virtualenv ? If so, can you tell me how ?如果是这样,你能告诉我怎么做吗?

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

You can make virtualenvwrapper use a custom Python binary instead of the one virtualenvwrapper is run with.您可以让 virtualenvwrapper 使用自定义 Python 二进制文件,而不是运行 virtualenvwrapper 的一个。 To do that you need to use VIRTUALENV_PYTHON variable which is utilized by virtualenv:为此,您需要使用 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.

The latest version of virtualenvwrapper is tested under Python3.2. 最新版virtualenvwrapper在Python3.2下测试。 Chances are good it will work with Python3.3 too.很有可能它也适用于 Python3.3。

virtualenvwrapper now lets you specify the python executable without the path. virtualenvwrapper 现在允许您指定没有路径的 python 可执行文件。

So (on OSX at least) mkvirtualenv --python=python3 nameOfEnvironment will suffice.所以(至少在 OSX 上) mkvirtualenv --python=python3 nameOfEnvironment就足够了。

On Ubuntu;在 Ubuntu 上; using mkvirtualenv -p python3 env_name loads the virtualenv with python3.使用mkvirtualenv -p python3 env_name使用mkvirtualenv -p python3 env_name加载 virtualenv。

Inside the env, use python --version to verify.在 env 中,使用python --version进行验证。

You can add this to your .bash_profile or similar:您可以将其添加到您的 .bash_profile 或类似文件中:

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

Then use mkvirtualenv3 instead of mkvirtualenv when you want to create a python 3 environment.当你想创建一个 python 3 环境时,然后使用mkvirtualenv3而不是mkvirtualenv

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.在 Ubuntu 的命令行中强制 mkvirtualenv 使用 python3 和 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.这是假设您在 /usr/bin/python3 中有 python3,在 /usr/local/bin/virtualenv-3.4 中有 virtualenv-3.4。

This post on the bitbucket issue tracker of virtualenvwrapper may be of interest.这篇关于virtualenvwrapper的 bitbucket 问题跟踪器的帖子可能会引起关注。 It is mentioned there that most of virtualenvwrapper's functions work with the venv virtual environments in Python 3.3.那里提到,大多数 virtualenvwrapper 的函数都适用于 Python 3.3 中的venv虚拟环境。

I added export VIRTUALENV_PYTHON=/usr/bin/python3 to my ~/.bashrc like 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

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

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