如何在 Windows 上运行多个 Python 版本 [英] How to run multiple Python versions on Windows

查看:38
本文介绍了如何在 Windows 上运行多个 Python 版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I had two versions of Python installed on my machine (versions 2.6 and 2.5). I want to run 2.6 for one project and 2.5 for another.

如何指定我要使用的内容?

How can I specify which I want to use?

我正在使用 Windows XP SP2.

I am working on Windows XP SP2.

推荐答案

运行不同的 Python 副本就像启动正确的可执行文件一样简单.你提到你已经从命令行启动了一个 python 实例,只需输入 python.

Running a different copy of Python is as easy as starting the correct executable. You mention that you've started a python instance, from the command line, by simply typing python.

这在 Windows 下的作用是拖网 %PATH% 环境变量,检查可执行文件,批处理文件 (.bat)、命令文件 (.cmd) 或其他一些要运行的可执行文件(这由 PATHEXT 环境变量控制),与给定的名称匹配.当它找到正确的文件运行时,该文件正在运行.

What this does under Windows, is to trawl the %PATH% environment variable, checking for an executable, either batch file (.bat), command file (.cmd) or some other executable to run (this is controlled by the PATHEXT environment variable), that matches the name given. When it finds the correct file to run the file is being run.

现在,如果您安装了两个 Python 版本 2.5 和 2.6,路径中将包含它们的两个目录,类似于 PATH=c:python2.5;c:python2.6,但 Windows 将在找到匹配项时停止检查路径.

Now, if you've installed two python versions 2.5 and 2.6, the path will have both of their directories in it, something like PATH=c:python2.5;c:python2.6 but Windows will stop examining the path when it finds a match.

您真正需要做的是显式调用一个或两个应用程序,例如 c:python2.5python.exec:python2.6python.exe.

What you really need to do is to explicitly call one or both of the applications, such as c:python2.5python.exe or c:python2.6python.exe.

另一种选择是为各自的python.exe创建一个快捷方式,调用其中一个python25和另一个python26;然后你可以简单地在命令行上运行 python25.

The other alternative is to create a shortcut to the respective python.exe calling one of them python25 and the other python26; you can then simply run python25 on your command line.

这篇关于如何在 Windows 上运行多个 Python 版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆