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

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

我正在使用Windows XP SP2。


当前回答

这里有一个解决方案:

首先,在你的电脑上安装你想要运行的所有版本。https://www.python.org/ 其次,创建您想使用的python版本的虚拟环境。 "py [python_version] -m venv [vrtual_environment_name]"示例:"py -3.9 -m venv env"

注意:你不需要运行"pip install virtualenv"

其他回答

这是一个简单而优雅的解决方案,可以轻松地运行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。优雅而简单。完成了。

使用批处理文件切换,在windows 7上简单高效。我用这个:

在环境变量对话框(C:\Windows\System32\SystemPropertiesAdvanced.exe)

在部分用户变量

添加了%pathpython%到path环境变量 删除了对python路径的任何引用

在部分系统变量

删除了对python路径的任何引用

我为每个python安装都创建了批处理文件(例如3.4 x64)

Name = SetPathPython34x64 !!ToExecuteAsAdmin.bat;-)只是为了记住。

文件的内容=

     Set PathPython=C:\Python36AMD64\Scripts\;C:\Python36AMD64\;C:\Tcl\bin

     setx PathPython %PathPython%

为了在版本之间切换,我以管理模式执行批处理文件。

! !这些更改对随后的命令提示符窗口“已打开”有效。!!!

所以我可以完全控制它。

我强烈推荐pyenv-win项目。

多亏了kirankotari的工作,现在我们有了一个Windows版本的pyenv。

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.

Cp c:\python27\bin\python.exe为python2.7.exe

Cp c:\python34\bin\python.exe为python3.4.exe

它们都在系统路径中,请选择要运行的版本

C:\Users\username>python2.7
Python 2.7.8 (default, Jun 30 2014, 16:03:49) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>>

C:\Users\username>python3.4
Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:38:22) [MSC v.1600 32 bit Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>