我的机器上安装了两个版本的Python(版本2.6和2.5)。我想在一个项目上运行2.6,在另一个项目上运行2.5。

我如何指定我想要使用哪个?

我正在使用Windows XP SP2。


当前回答

例如,对于3.6版本,键入py -3.6。 如果你也有32位和64位版本,你可以输入py -3.6-64或py -3.6-32。

其他回答

您可以通过Anaconda Navigator图形化地创建不同的python开发环境。 在使用不同的python版本时,我也遇到了同样的问题,所以我使用anaconda navigator来创建不同的python开发环境,并在每个环境中使用不同的python版本。

下面是相关的帮助文档。

https://docs.anaconda.com/anaconda/navigator/tutorials/manage-environments/

这里有一个快速的方法:

进入要运行的python版本的目录 右键单击python.exe 选择“创建快捷方式” 给快捷方式起个名字(我用p27, p33等) 移动快捷方式到你的主目录(C:\Users\你的名字) 打开命令提示符,输入name_of_your_shortcut.lnk(我使用p27.lnk)

Using the Rapid Environment Editor you can push to the top the directory of the desired Python installation. For example, to start python from the c:\Python27 directory, ensure that c:\Python27 directory is before or on top of the c:\Python36 directory in the Path environment variable. From my experience, the first python executable found in the Path environment is being executed. For example, I have MSYS2 installed with Python27 and since I've added C:\MSYS2 to the path before C:\Python36, the python.exe from the C:\MSYS2.... folder is being executed.

从Python 3.3开始,Windows有官方的Python启动器(http://www.python.org/dev/peps/pep-0397/)。现在,您可以使用#!pythonX来确定在Windows上需要的解释器版本。在我的另一条评论中查看更多细节,或阅读PEP 397。

概要:py script.py会启动#!如果#!不见了。py -3 script.py启动Python 3。

安装python C: \ Python27 C: \ Python36 环境变量 PYTHON2_HOME: C: \ Python27 PYTHON3_HOME: C: \ Python36 路径:% PYTHON2_HOME %, % PYTHON2_HOME % \脚本;% PYTHON3_HOME %, % PYTHON3_HOME % \脚本; 文件重命名 C:\Python27\python2.exe→C:\Python27\python2.exe C:\Python36\python3.exe→C:\Python36\python3.exe 皮普 Python2 -m PIP安装包 Python3 -m PIP安装包