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

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

我正在使用Windows XP SP2。


当前回答

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.
>>>

其他回答

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

下面是相关的帮助文档。

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

我认为这个答案可能对拥有多个python版本并希望使用pipenv创建虚拟环境的其他人有所帮助。

进入工程目录,执行py -[python版本]PIP install pipenv,例如:py -3.6 PIP install pipenv 运行pipenv——python [version]以创建所需python版本的虚拟环境。示例:pipenv——python 3.6 运行pipenv shell激活虚拟环境。

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.

这里有一个解决方案:

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

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

我强烈推荐pyenv-win项目。

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