Multiple python versions using virtualenv -p (and

2019-05-29 02:45发布

I'd like to use multiple versions of python (2.5 and 2.7 is what I need, but would be nice to have 3.2 also). On Windows XP!

I'd like to use virtualenvwrapper-win instead of virtualenv -p

Here's the method for Unix: Use different Python version with virtualenv

Does the same method apply for virtualenvwrapper-win? The source for mkvirtualenv seems to pass the arguments to virtualenv on line 35: https://github.com/davidmarble/virtualenvwrapper-win/blob/master/scripts/mkvirtualenv.bat

I thought I would ask if anyone has done this (and to tell others that they can do this) by asking this question before trying it (and potentially messing up my python environment).

If you have done this, any things to watch out for? Can I use the ActiveState python install for my second python version?

3条回答
乱世女痞
2楼-- · 2019-05-29 03:10

I found this project to very helpful.

https://github.com/pyenv/pyenv

It automates the installation and management of multiple python versions.
So you could install python 2.4.3 and 2.5.2 and 2.7.1.
You can then switch between python versions you want to run and test your python apps with.

It also has helper scripts
https://github.com/pyenv/pyenv-virtualenvwrapper
https://github.com/pyenv/pyenv-virtualenv

查看更多
ら.Afraid
3楼-- · 2019-05-29 03:12

Regarding installing additional versions (multiple versions) of python, I installed ActiveState python 2.7 and 3.3. They installed in different directories in the c:/ area.

Currently, 2.7 installs as the default python. The older python can be accessed as python25 in the command line.

Python 3.3 does not install as the default python. Also, you have to use the full path name or add it to the path yourself (or enable the option during the install process).

Overall, however, it was quite easy to install multiple versions of python using ActiveState.

For virtualenv:

python 2.7: had some problems with pip not present. Seems to be able to solve it by running "easy_install pip" inside the virtualenv.

python 3.3: had problems with mkvirtualenv command: it causes python to fail! I did not pursue this since I don't need it now (but if anyone knows what the problem is and the solution that would be great!)

Oct 13, 2013 edit: I had to re-install virtualenvwrapper-win into python27 environment. After that, python27 virtualenv was working ok.

查看更多
Explosion°爆炸
4楼-- · 2019-05-29 03:25

Virtualenvwrapper passes command line flags directly to virtualenv. mkvirtualenv --python=c:/your/path/to/python2.5 will set up your virtual environment with python 2.5. I've done it many times.

That said, it will save you trouble later if you install as few packages outside of your virtual environment as possible. (you can always delete a virtual environment without too much trouble, it's harder to completely remove packages/change paths outside of one) Multiple versions of python can make pip and easy_install do strange things. Inside a virtual environment, you don't have to worry about that.

You don't need to worry about messing up your python environment, at least not with virtualenv, it's easy to add or remove virtual environments. The --python flag will work with any python executable (it just sets up a different set of scripts within the virtual environment), so it should work with ActiveState.

查看更多
登录 后发表回答