我的大部分编程都是用Python 3完成的。但现在我需要使用Python成像库(PIL)、ImageMagick和wxPython,所有这些都需要Python 2.x。

我可以要两个Python 2吗?3. Python。Windows 7?当我运行一个脚本时,我如何“选择”哪个版本的Python应该运行它?上述程序是否能够处理同时安装的多个Python版本?我已经花了好几个小时来寻找如何做到这一点,但无济于事。

谢谢。


当前回答

只有在Python IDE中运行代码才有效

我的windows操作系统上同时安装了Python 2.7和Python 3.3。如果我试图启动一个文件,它通常会在python 2.7 IDE上打开。我如何解决这个问题,是当我选择在python 3.3上运行我的代码时,我打开python 3.3 IDLE(python GUI),选择文件,用IDLE打开我的文件并保存它。然后,当我运行我的代码时,它运行到我当前打开它的IDLE。反之亦然。

其他回答

如果您使用Anaconda Python,您可以轻松地安装各种环境。

假设你已经安装了Anaconda Python 2.7,你想要一个Python 3.4环境:

conda create -n py34 python=3.4 anaconda

然后激活环境:

activate py34

以及deactive:

deactivate py34

(对于Linux,您应该使用源代码激活py34。)

链接:

下载蟒蛇

环境说明

我按照这里的说明分三步做到了这一点:这都是从这里直接获取的:http://ipython.readthedocs.io/en/stable/install/kernel_install.html。我目前正在运行Python 2。已安装Anaconda 4.2.13。

1)首先安装最新版本的python:

conda create -n python3 python=3 ipykernel

2)下一步激活python3

activate python3

3)安装内核:

python -m ipykernel install --user

如果你已经安装了python3,想要安装python2,请切换上面的python2和python3。当你打开一个新的笔记本时,你现在可以在python2或python3之间进行选择。

You can install multiple versions of Python one machine, and during setup, you can choose to have one of them associate itself with Python file extensions. If you install modules, there will be different setup packages for different versions, or you can choose which version you want to target. Since they generally install themselves into the site-packages directory of the interpreter version, there shouldn't be any conflicts (but I haven't tested this). To choose which version of python, you would have to manually specify the path to the interpreter if it is not the default one. As far as I know, they would share the same PATH and PYTHONPATH variables, which may be a problem.

注:我使用的是Windows XP。我不知道其他版本是否会有这些变化,但我看不出有任何理由会发生变化。

我在windows中有多个版本。 我只是改变了我不是默认版本的exe名称。

Python.exe——> python26.exe python .exe——> pythonw26.exe

至于软件包安装程序,大多数exe安装程序也允许您选择python安装程序来添加软件包。 对于手动安装,检查——prefix选项来定义包应该安装在哪里:

http://docs.python.org/install/index.html#alternate-installation-windows-the-prefix-scheme

以下是你可以做的:

安装cmd。 打开并使用cmd终端,就像你会使用cmd终端一样。 使用命令alias创建命令别名。

我做了以下事情:

alias python2 = c:\python27\python.exe
alias python3 = c:\python34\python.exe

就是这样!: -)