如何安装两个Python 2。x和Python 3。x在Windows 7中
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.
我在python3里做了大部分的编程工作。在Windows 7上,但是现在我需要使用Python映像库(PIL)、ImageMagick和wxPython,所有这些都需要Python 2.x。
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.
我能同时拥有两条蟒蛇吗?x和Python 3。x安装在Windows 7?当我运行一个脚本时,我如何“选择”哪个版本的Python应该运行它?上述程序能够同时处理多个版本的Python吗?我已经找了好几个小时了,怎么做都没用。
Thanks.
谢谢。
19 个解决方案
#1
115
I found that the formal way to do this is as follows:
我发现正式的做法如下:
Just install two (or more, using their installers) versions of Python on Windows 7 (for me work with 3.3 and 2.7).
只需在Windows 7上安装两个(或更多,使用安装程序)Python版本(对我来说是3.3和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
To launch a script in a particular interpreter, add the following shebang (beginning of script):
要在特定解释器中启动脚本,添加以下shebang(脚本开始):
#! 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
To launch the default interpreter (defined by the PY_PYTHON variable):
要启动默认解释器(由PY_PYTHON变量定义):
> py
Resources
资源
Documentation: Using Python on Windows
文档:在Windows上使用Python。
PEP 397 - Python launcher for Windows
PEP 397 - Windows的Python启动程序。
更多相关文章
- Python脚本如何获取当前环节和用户等信息
- python mysql 导出到mongodb脚本
- 脚本结束后如何运行进程并退出?
- 如何获得正在运行的Python脚本的路径?(复制)
- Shell脚本更改带变量的目录
- wdcp/wdlinux一键包的php5.3版本添加Zend.so 和Soap.so
- Linux(Debian)设置开机自启动脚本
- 《Linux命令行与shell脚本》笔记--第5章:使用Linux环境变量
- linux环境,Tomcat 指定运行时 jdk的版本