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

查看:292
本文介绍了如何在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:\python\2.5; c:\python\2.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:\python\2.5;c:\python\2.6 but Windows will stop examining the path when it finds a match.

您真正需要做的是显式调用一个或两个应用程序,例如 c:\python\2.5\ \python.exe c:\python\2.6\python.exe

What you really need to do is to explicitly call one or both of the applications, such as c:\python\2.5\python.exe or c:\python\2.6\python.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天全站免登陆