6

我想在我的盒子里运行多个 Python 版本。Python中有没有类似版本管理器的东西,我可以在多个Python版本之间切换而不必调用python二进制文件的完整路径?我已经尝试过 virtualenv,它似乎只涵盖了运行多个 python 库版本的问题。

谢谢你的帮助。

4

3 回答 3

9

从 bash 调用 python 时,您可以尝试使用别名。

user@machine:~$ alias python1234='/usr/bin/python2.5'
user@machine:~$ python1234
Python 2.5.4 (r254:67916, Jan 20 2010, 21:44:03) 
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 

假设您有一个名为 script.py 的脚本,其内容如下:

import sys
print sys.version

因此,使用不同版本的 python 启动脚本如下所示:

user@machine:~$ python script.py 
2.6.2 (release26-maint, Apr 19 2009, 01:56:41) 
[GCC 4.3.3]
user@machine:~$ python1234 script.py 
2.5.4 (r254:67916, Jan 20 2010, 21:44:03) 
[GCC 4.3.3]
于 2010-10-06T22:13:33.013 回答
7

I use virtualenv to keep track of different environments I need for my projects. I may setup django 1.0 in one environment or django 1.2 for another. You can use it to set which version of python you'd like to use in a particular environment as well. Here's the link to the site which has great samples and tutorials for how to get running: http://pypi.python.org/pypi/virtualenv

于 2010-10-06T23:04:51.443 回答
4

您不必使用完整路径。

user@machine:$ python2.5
Python 2.5.5 (r255:77872, Sep 14 2010, 17:16:34) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 

user@machine:$ python2.6
Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 

这是否回答你的问题?

于 2010-10-06T22:35:05.410 回答