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

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

谢谢。


当前回答

Windows版本有Python启动器,请参阅3.4节。Windows Python启动器

其他回答

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

I just had to install them. Then I used the free (and portable) soft at http://defaultprogramseditor.com/ under "File type settings"/"Context menu"/search:"py", chose .py file and added an 'open' command for the 2 IDLE by copying the existant command named 'open with IDLE, changing names to IDLE 3.4.1/2.7.8, and remplacing the files numbers of their respective versions in the program path. Now I have just to right click the .py file and chose which IDLE I want to use. Can do the same with direct interpreters if you prefer.

安装Python后检查系统环境变量,首先在PATH变量中应该是python3的目录,然后是python2。

最先匹配的路径变量就是Windows使用的路径变量。

一如既往,py -2将在此场景中启动python2。

我自己也遇到过这个问题,我把我的启动器放在。bat中,这样你就可以选择你想要启动的版本。

唯一的问题是你的.py必须在python文件夹中,但不管怎样,这里是代码:

对于Python2

@echo off
title Python2 Launcher by KinDa
cls
echo Type the exact version of Python you use (eg. 23, 24, 25, 26)
set/p version=
cls
echo Type the file you want to launch without .py (eg. hello world, calculator)
set/p launch=
path = %PATH%;C:\Python%version%
cd C:\Python%version%
python %launch%.py
pause

对于Python3

@echo off
title Python3 Launcher by KinDa
cls
echo Type the exact version of Python you use (eg. 31, 32, 33, 34)
set/p version=
cls
echo Type the file you want to launch without .py (eg. hello world, calculator)
set/p launch=
cls
set path = %PATH%:C:\Python%version%
cd C:\Python%version%
python %launch%.py
pause

将它们保存为。bat,并按照里面的说明进行操作。

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