我的机器上安装了两个版本的Python(版本2.6和2.5)。我想在一个项目上运行2.6,在另一个项目上运行2.5。
我如何指定我想要使用哪个?
我正在使用Windows XP SP2。
我的机器上安装了两个版本的Python(版本2.6和2.5)。我想在一个项目上运行2.6,在另一个项目上运行2.5。
我如何指定我想要使用哪个?
我正在使用Windows XP SP2。
当前回答
使用批处理文件切换,在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%
为了在版本之间切换,我以管理模式执行批处理文件。
! !这些更改对随后的命令提示符窗口“已打开”有效。!!!
所以我可以完全控制它。
其他回答
从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。
根据@alexander,你可以像下面这样创建一组符号链接。把它们放在包含在路径中的某个地方,这样就可以很容易地调用它们
> cd c:\bin
> mklink python25.exe c:\python25\python.exe
> mklink python26.exe c:\python26\python.exe
只要c:\bin或者你放置它们的地方在你的路径中,你现在就可以去了
> python25
显示已安装的python
py -0
使用python版本来做某事
py -*version*
ex.
py -3.8 venv venv
将在python 3.8中创建虚拟环境
注意:
python -0
or
python -3.8
不工作,我认为它必须是“py”
假设我们安装了python 3.7和python 3.6。
它们默认分别存储在以下文件夹中。
C:\Users\name\AppData\Local\Programs\Python\Python36 C:\Users\name\AppData\Local\Programs\Python\Python37
如果我们想在上述任何特定环境中使用CMD提示符来安装/运行命令,请这样做:
在上面的每个文件夹中都应该有python.exe。
因此,当我们尝试运行任何文件的ex.(见image1) python hello.py。我们称之为相应的python.exe。默认情况下,它选择较低版本的文件。(在这种情况下,它将从python 3.6使用)
图像
如果我们想使用python3.7运行。只需更改.exe文件名。例如,如果我更改为python37.exe,并且我想使用python3.7来运行hello.py
我将使用python37 hello.py。或者如果我想在默认情况下使用python3.7,我会将python3.6文件夹中的python.exe文件名更改为其他文件。这样每次我只使用python hello.py时,它都会使用python3.7
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.