我的机器上安装了两个版本的Python(版本2.6和2.5)。我想在一个项目上运行2.6,在另一个项目上运行2.5。
我如何指定我想要使用哪个?
我正在使用Windows XP SP2。
我的机器上安装了两个版本的Python(版本2.6和2.5)。我想在一个项目上运行2.6,在另一个项目上运行2.5。
我如何指定我想要使用哪个?
我正在使用Windows XP SP2。
当前回答
只需调用正确的可执行文件
其他回答
显示已安装的python
py -0
使用python版本来做某事
py -*version*
ex.
py -3.8 venv venv
将在python 3.8中创建虚拟环境
注意:
python -0
or
python -3.8
不工作,我认为它必须是“py”
只需调用正确的可执行文件
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时,它不会覆盖其他主要版本的其他安装。安装Python 2.5。x不会覆盖Python 2.6。尽管安装2.6.6会覆盖2.6.5。
所以你可以安装它。然后调用你想要的Python版本。例如:
C:\Python2.5\Python.exe
用于windows上的Python 2.5和
C:\Python2.6\Python.exe
适用于windows上的Python 2.6,或者
/usr/local/bin/python-2.5
or
/usr/local/bin/python-2.6
Windows Unix(包括Linux和OS X)。
当你在Unix(包括Linux和OS X)上安装时,你会安装一个通用的python命令,这将是你安装的最后一个命令。这基本上不是问题,因为大多数脚本会显式调用/usr/local/bin/python2.5或其他东西来防止这种情况发生。但是如果你不想这样做,你可能不想这样做,你可以这样安装它:
./configure
make
sudo make altinstall
注意,“altinstall”表示它将安装该命令,但不会替换python命令。
据我所知,在Windows上你不会得到一个全局python命令,所以这不是一个问题。
从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。