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

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

谢谢。


当前回答

我已经在windows 10pro上安装了python 2.7.13和python 3.6.1,当我尝试pip2或pip3时,我得到了相同的“致命错误”。

为了纠正这一点,我去python2和python3文件的python.exe的位置,并为每个文件创建一个副本,然后根据安装文件夹中的python版本将每个副本重命名为python2.exe和python3.exe。因此,我在每个python安装文件夹中都有一个python.exe文件和一个python2.exe或python3.exe,这取决于python版本。

当我输入pip2或pip3时,这解决了我的问题。

其他回答

我所做的就是下载2.7.6和3.3.4。Python 3.3.4提供了在环境变量中添加路径的选项,这样就完成了。所以基本上我只是手动添加了Python 2.7.6。

如何……

Start > in the search type in environment select "Edit environment variables to your account"1 Scroll down to Path, select path, click edit. Add C:\Python27; so you should have paths to both versions of Python there, but if you don't this you can easily edit it so that you do..... C:\Python27;C:\Python33; Navigate to the Python27 folder in C:\ and rename a copy of python.exe to python2.exe Navigate to the Python34 folder in C:\ and rename a copy of python.exe to python3.exe Test: open up commmand prompt and type python2 ....BOOM! Python 2.7.6. exit out. Test: open up commmand prompt and type python3 ....BOOM! Python 3.4.3. exit out.

注意:(为了不破坏步骤4和5中的pip命令,将python.exe的副本保存在与重命名文件相同的目录中)

我已经在windows 10pro上安装了python 2.7.13和python 3.6.1,当我尝试pip2或pip3时,我得到了相同的“致命错误”。

为了纠正这一点,我去python2和python3文件的python.exe的位置,并为每个文件创建一个副本,然后根据安装文件夹中的python版本将每个副本重命名为python2.exe和python3.exe。因此,我在每个python安装文件夹中都有一个python.exe文件和一个python2.exe或python3.exe,这取决于python版本。

当我输入pip2或pip3时,这解决了我的问题。

在另一个上面安装最常用的一个(我的例子是3.3)。这将迫使IDLE使用您想要的那个。

或者(来自python3.3 README):

安装多个版本

On Unix and Mac systems if you intend to install multiple versions of Python using the same installation prefix (--prefix argument to the configure script) you must take care that your primary python executable is not overwritten by the installation of a different version. All files and directories installed using "make altinstall" contain the major and minor version and can thus live side-by-side. "make install" also creates ${prefix}/bin/python3 which refers to ${prefix}/bin/pythonX.Y. If you intend to install multiple versions using the same prefix you must decide which version (if any) is your "primary" version. Install that version using "make install". Install all other versions using "make altinstall".

例如,如果你想安装Python 2.6, 2.7和3.3,其中2.7是 主版本,您将在2.7构建目录中执行“make install” 而其他的则是“make altinstall”。

我按照这里的说明分三步做到了这一点:这都是从这里直接获取的: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之间进行选择。

我在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