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启动程序。

更多相关文章

  1. Python脚本如何获取当前环节和用户等信息
  2. python mysql 导出到mongodb脚本
  3. 脚本结束后如何运行进程并退出?
  4. 如何获得正在运行的Python脚本的路径?(复制)
  5. Shell脚本更改带变量的目录
  6. wdcp/wdlinux一键包的php5.3版本添加Zend.so 和Soap.so
  7. Linux(Debian)设置开机自启动脚本
  8. 《Linux命令行与shell脚本》笔记--第5章:使用Linux环境变量
  9. linux环境,Tomcat 指定运行时 jdk的版本

随机推荐

  1. 学好Android开发的几条建议-----选好教材
  2. android防止反编译系列:如何对抗JD-GUI
  3. Android中的BatteryService及相关组件
  4. 获取Android设备的唯一序列号
  5. android textview空格占位符以及一些其他
  6. Android编程学习笔记 之 ListActivity源
  7. Android之SQLite数据库篇
  8. 无法将视图添加到相对布局
  9. 20169221 2016-2017-2《移动平台与androi
  10. 键盘打开时,带有片段的活动不会调整大小