如何在 Windows 中同时安装 Python 2.x 和 Python 3.x [英] How to install both Python 2.x and Python 3.x in Windows

查看:34
本文介绍了如何在 Windows 中同时安装 Python 2.x 和 Python 3.x的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Windows 7 上使用 Python 3.x 进行大部分编程,但现在我需要使用 Python 成像库 (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

启动特定的解释器:

> py -2

启动默认解释器(由 PY_PYTHON 变量定义):

To launch the default interpreter (defined by the PY_PYTHON variable):

> py

资源

文档:在 Windows 上使用 Python

PEP 397 - 适用于 Windows 的 Python 启动器

PEP 397 - Python launcher for Windows

这篇关于如何在 Windows 中同时安装 Python 2.x 和 Python 3.x的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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