virtualenvwrapper and Python 3

2020-05-10 23:56发布

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 ?

9条回答
别忘想泡老子
2楼-- · 2020-05-11 00:23

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楼-- · 2020-05-11 00:24

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

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

查看更多
男人必须洒脱
4楼-- · 2020-05-11 00:28

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.

查看更多
Anthone
5楼-- · 2020-05-11 00:30

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.

查看更多
做个烂人
6楼-- · 2020-05-11 00:33

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

查看更多
做自己的国王
7楼-- · 2020-05-11 00:33

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.

查看更多
登录 后发表回答