我的机器上安装了两个版本的Python(版本2.6和2.5)。我想在一个项目上运行2.6,在另一个项目上运行2.5。
我如何指定我想要使用哪个?
我正在使用Windows XP SP2。
我的机器上安装了两个版本的Python(版本2.6和2.5)。我想在一个项目上运行2.6,在另一个项目上运行2.5。
我如何指定我想要使用哪个?
我正在使用Windows XP SP2。
当前回答
根据@alexander,你可以像下面这样创建一组符号链接。把它们放在包含在路径中的某个地方,这样就可以很容易地调用它们
> cd c:\bin
> mklink python25.exe c:\python25\python.exe
> mklink python26.exe c:\python26\python.exe
只要c:\bin或者你放置它们的地方在你的路径中,你现在就可以去了
> python25
其他回答
从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。
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.
只需调用正确的可执行文件
这是一个简单而优雅的解决方案,可以轻松地运行2个或更多不同版本的python,而无需在Windows中使用脚本。无论python的版本是什么,它都将从命令提示符开始。
我有python 3.6.6和3.9版本。环境变量路径是正常的,在安装每个版本的python时自动添加。
最好使用“所有用户”选项安装python。这样,python将简单地安装到:
C:\program files\python36
C:\program files\python39
打开每个python文件夹,找到python.exe文件。将python.exe文件复制并粘贴到相同的文件夹中。然后小心地将副本重命名为:
python36.exe
python39.exe
打开并编辑“环境变量”。添加4个新的用户变量。
C:\Program Files\Python36\Scripts
C:\Program Files\Python36\python36.exe
C:\Program Files\Python39\Scripts
C:\Program Files\Program39\python39.exe
保存并退出“环境变量”。
打开一个新的命令提示符终端窗口。要运行一个或另一个版本的python,输入:
python36
python39
通过重复上面所示的操作,可以轻松添加更多版本的python。优雅而简单。完成了。
您可以通过Anaconda Navigator图形化地创建不同的python开发环境。 在使用不同的python版本时,我也遇到了同样的问题,所以我使用anaconda navigator来创建不同的python开发环境,并在每个环境中使用不同的python版本。
下面是相关的帮助文档。
https://docs.anaconda.com/anaconda/navigator/tutorials/manage-environments/