如何在Windows中同时安装Python 2.x和Python 3.x [英] How to install both Python 2.x and Python 3.x in Windows
问题描述
我在Windows 7上使用Python 3.x进行大部分编程,但是现在我需要使用Python Imaging Library(PIL),ImageMagick和wxPython,所有这些都需要Python 2.x.
I do most of my programming in Python 3.x on Windows 7, but now I need to use the Python Imaging Library (PIL), ImageMagick, and wxPython, all of which require Python 2.x.
我可以在Windows 7中同时安装Python 2.x和Python 3.x吗?当我运行脚本时,如何选择"应该运行哪个版本的Python?前面提到的程序能否处理一次安装的多个版本的Python?我已经搜索了好几个小时,却无济于事.
Can I have both Python 2.x and Python 3.x installed in Windows 7? When I run a script, how would I "choose" which version of Python should run it? Will the aforementioned programs be able to handle multiple versions of Python installed at once? I have searched for hours and hours for how to do this to no avail.
谢谢.
推荐答案
我发现执行此操作的正式方法如下:
I found that the formal way to do this is as follows:
只需在Windows 7上安装两个(或更多,使用其安装程序)Python版本(对我而言,使用3.3和2.7).
Just install two (or more, using their installers) versions of Python on Windows 7 (for me work with 3.3 and 2.7).
按照下面的说明,根据您的需要更改参数.
Follow the instuctions below, changing the parameters for your needs.
创建以下环境变量(默认为双击):
Create the following environment variable (to default on double click):
Name: PY_PYTHON
Value: 3
要在特定的解释器中启动脚本,请添加以下shebang(脚本开始):
To launch a script in a particular interpreter, add the following shebang (beginning of script):
#! python2
要使用特定的解释器执行脚本,请使用以下提示命令:
To execute a script using a specific interpreter, use the following prompt command:
> py -2 MyScript.py
要启动特定的解释器,请执行以下操作:
To launch a specific interpreter:
> py -2
要启动默认解释器(由PY_PYTHON变量定义):
To launch the default interpreter (defined by the PY_PYTHON variable):
> py
资源
PEP 397 -Windows的Python启动器
PEP 397 - Python launcher for Windows
这篇关于如何在Windows中同时安装Python 2.x和Python 3.x的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!