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启动程序。
#2
50
What I did was download both 2.7.6 and 3.3.4. Python 3.3.4 has the option to add the path to it in the environment variable so that was done. So basically I just manually added Python 2.7.6.
我所做的是下载2.7.6和3.3.4。Python 3.3.4可以选择将路径添加到环境变量中,这样就完成了。所以基本上我只是手动添加了Python 2.7.6。
How to...
如何……
-
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;
将C:\ Python27;所以你应该有两条路径到这两个版本的Python,但是如果你不这样做的话,你可以很容易地编辑它,这样你就可以做了。C:\ Python27;C:\ Python33;
-
Navigate to the Python27 folder in C:\ and change python.exe to python2.exe
导航到C:\和更改python中的Python27文件夹。exe,python2.exe
-
Navigate to the Python34 folder in C:\ and change python.exe to python3.exe
导航到C:\和更改python中的Python34文件夹。exe,python3.exe
-
Test: open up commmand prompt and type python2 ....BOOM! Python 2.7.6. exit out.
测试:打开commmand提示和类型python2 ....繁荣!Python 2.7.6。退出了。
-
Test: open up commmand prompt and type python3 ....BOOM! Python 3.4.3. exit out.
测试:打开commmand提示和类型python3 ....繁荣!Python 3.4.3。退出了。
Note: (to not break pip commands before following step 4 and 5 keep copy of python.exe in the same directory and renamed file)
注意:(在第4步和第5步保持python拷贝之前,不要破坏pip命令)。在同一个目录中,并重命名文件)
#3
44
I have multiple versions in windows. I just change the exe name of the version I'm not defaulting to.
我在windows中有多个版本。我只是更改了我不默认的版本的exe名称。
python.exe --> python26.exe
python。exe - - > python26.exe
pythonw.exe --> pythonw26.exe
pythonw。exe - - > pythonw26.exe
As for package installers, most exe installers allow you to choose the python install to add the package too. For manual installation check out the --prefix option to define where the package should be installed:
对于包安装程序,大多数exe安装程序允许您选择python安装来添加包。手动安装检查——前缀选项,以定义应该安装包的位置:
http://docs.python.org/install/index.html#alternate-installation-windows-the-prefix-scheme
http://docs.python.org/install/index.html alternate-installation-windows-the-prefix-scheme
#4
22
If you use Anaconda Python, you can easily install various environments.
如果您使用Anaconda Python,您可以轻松地安装各种环境。
Say you had Anaconda Python 2.7 installed and you wanted a python 3.4 environment:
假设您已经安装了Anaconda Python 2.7,您想要一个Python 3.4环境:
conda create -n py34 python=3.4 anaconda
Then to activate the environment:
然后激活环境:
activate py34
And to deactive:
和不激活:
deactivate py34
(With Linux, you should use source activate py34
.)
(使用Linux,您应该使用source activate py34。)
Links:
链接:
下载Python蟒蛇
说明环境
#5
6
Starting version 3.3 Windows version has Python launcher, please take a look at section 3.4. Python Launcher for Windows
开始版本3.3 Windows版本有Python启动器,请查看第3.4节。Python启动Windows
#6
5
Here's what you can do:
以下是你能做的:
Install cmder. Open and use Cmder as you would with you cmd terminal. Use the command alias to create command aliases.
安装cmd。像你和cmd终端一样打开和使用Cmder。使用命令别名创建命令别名。
I did the following:
我做了以下几点:
alias python2 = c:\python27\python.exe
alias python3 = c:\python34\python.exe
And that's it! ;-)
这是它!:-)
#7
3
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.
您可以安装Python one machine的多个版本,在安装过程中,您可以选择让其中之一与Python文件扩展相关联。如果您安装了模块,将会有不同版本的不同安装包,或者您可以选择您想要攻击的版本。由于它们通常安装在解释器版本的站点包目录中,所以不应该有任何冲突(但我没有测试过这个)。要选择python的哪个版本,如果不是默认的解释器,则必须手动指定解释器的路径。据我所知,它们将共享相同的路径和PYTHONPATH变量,这可能是一个问题。
Note: I run Windows XP. I have no idea if any of this changes for other versions, but I don't see any reason that it would.
注意:我运行Windows XP。我不知道其他版本是否有这种变化,但我看不出有什么原因。
#8
2
What I have done on my own windows computer where I have Python 2.7 and Python 3.4 installed is I wrote a simple .bat file in the same directory as my Python.exe files. They look something like,
我在自己的windows电脑上所做的是,我在那里安装了Python 2.7和Python 3.4,我在同一个目录下编写了一个简单的.bat文件,就像我的Python一样。exe文件。他们看起来像,
cmd /k "c:\python27\python.exe" %*
The %* allows you to add arguments (Python files) afterwards. I believe /k keeps the prompt open after it finishes running the script. Then I save that as python27.bat Then I go to my Python 3 directory and make a bat file there. Now in my command line I can write
%*允许您在之后添加参数(Python文件)。我相信/k在运行脚本后保持提示打开。然后我把它保存为python27。然后我转到Python 3目录,在那里做一个bat文件。现在在我的命令行中,我可以写。
Python27 helloworld.py
Or
或
Python34 helloworld.py
And they will run in their respective versions of Python. Make sure that c:\python27 and c:\python34 are in your environment variables.
它们将在各自版本的Python中运行。确保c:\python27和c:\python34在您的环境变量中。
I got my answer from here
我从这里得到了答案。
#9
2
I did this in three steps by following the instructions here: This is all taken directly from here: http://ipython.readthedocs.io/en/stable/install/kernel_install.html. I'm currently running Python 2.x on Windows 8 and have Anaconda 4.2.13 installed.
我按照这里的说明进行了三个步骤:这都是直接从这里得到的:http://ipyth.readthedocs.io/en/stable/install/kernel_install.html。我现在运行的是python2。在Windows 8上安装了Anaconda 4.2.13。
1) First install the latest version of python:
1)首先安装最新版本的python:
conda create -n python3 python=3 ipykernel
2) Next activate python3
2)下一个激活python3
activate python3
3) Install the kernel:
3)安装内核:
python -m ipykernel install --user
If you have Python 3 installed and want to install 2, switch the 2 and the 3 above. When you open a new notebook, you can now choose between Python 2 or 3.
如果您安装了Python 3,并希望安装2,请将上面的2和3切换。当你打开一个新笔记本时,你现在可以在Python 2或3中选择。
#10
1
Check your system environment variables after installing Python, python 3's directories should be first in your PATH variable, then python 2.
在安装Python之后检查系统环境变量,Python 3的目录应该首先在PATH变量中,然后是python2。
Whichever path variable matches first is the one Windows uses.
无论哪一个路径变量匹配首先是一个窗口使用。
As always py -2 will launch python2 in this scenario.
通常py -2会在这个场景中启动python2。
#11
1
I actually just thought of an interesting solution. While Windows will not allow you to easily alias programs, you can instead create renamed batch files that will call the current program.
我只是想到了一个有趣的解决方案。虽然Windows不会允许您轻松地使用别名程序,但是您可以创建重命名的批处理文件,它将调用当前程序。
Instead of renaming the executable which will break a lot of thing including pip, create the file python2.bat in the same directory as the python2.exe. Then add the following line:
不要重命名可执行文件,它会破坏很多东西,包括pip,创建文件python2。bat在与python2.exe相同的目录中。然后添加以下一行:
%~dp0python %*
What does this archaic syntax mean? Well, it's a batch script, (Windows version of bash). %~dp0 gets the current directory and %* will just pass all the arguments to python that were passed to the script.
这个古老的语法是什么意思?这是一个批处理脚本(bash的Windows版本)。%~dp0得到当前目录,%*将把所有参数传递给脚本。
Repeat for python3.bat
重复做python3.bat
You can also do the same for pip and other utilities, just replace the word python in the file with pip or whathever the filename. The alias will be whatever the file is named.
您也可以对pip和其他实用程序执行相同的操作,只需在文件中以pip或whathever文件名替换python。该别名将是该文件的名称。
Best of all, when added to the PATH, Windows ignores the extension so running
最重要的是,当添加到路径时,Windows忽略了扩展,因此运行。
python3
Will launch the python3 version and and the command python2 will launch the python2 version.
将启动python3版本,命令python2将启动python2版本。
BTW, this is the same technique Spyder uses to add itself to the path on Windows. :)
顺便说一下,这是Spyder用来在Windows上添加自己的技术。:)
#12
1
I have encountered that problem myself and I made my launchers in a .bat so you could choose the version you want to launch.
我自己也遇到过这个问题,我把我的发射器放进了一个。bat,这样你就可以选择你想要发射的版本了。
The only problem is your .py must be in the python folder, but anyway here is the code:
唯一的问题是你的。py必须在python文件夹中,但是这里是代码:
For Python2
对于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
For Python3
对于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
Save them as .bat and follow the instructions inside.
将它们保存为。bat,并按照里面的说明操作。
#13
0
Install the one you use most (3.3 in my case) over the top of the other. That'll force IDLE to use the one you want.
在我的例子中,安装你最常用的一个(在我的例子中是3.3)。这将迫使IDLE使用你想要的那个。
Alternatively (from the python3.3 README):
或者(从python3.3 README):
Installing multiple versions
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".
在Unix和Mac系统上,如果您打算使用相同的安装前缀(——前缀参数到configure脚本)安装多个版本的Python,那么您必须注意,您的主Python可执行文件并没有被安装不同版本所覆盖。使用“make altinstall”安装的所有文件和目录都包含主要和次要版本,因此可以并排共存。“make install”还可以创建${前缀}/bin/python3,这是指${前缀}/bin/pythonX.Y。如果您打算使用相同的前缀安装多个版本,则必须决定哪个版本(如果有的话)是您的“主要”版本。使用“make Install”安装该版本。使用“make altinstall”安装所有其他版本。
For example, if you want to install Python 2.6, 2.7 and 3.3 with 2.7 being the primary version, you would execute "make install" in your 2.7 build directory and "make altinstall" in the others.
例如,如果您希望安装Python 2.6、2.7和3.3,其中2.7是主要版本,那么您将在2.7构建目录中执行“make install”,在其他版本中“make altinstall”。
#14
0
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.
我只需要安装它们。然后我使用了*(便携式)在http://defaultprogramseditor.com/上软下“文件类型设置”/“上下文菜单”搜索:“py”,选择. py文件并添加一个“打开”命令2闲置通过复制existant命令的名为“开放与闲置,改变名字空闲3.4.1/2.7.8,和remplacing文件数量的各自版本的程序路径。现在,我只需右键单击.py文件并选择要使用的空闲文件。如果你喜欢,也可以直接翻译。
#15
0
What i have done personally is very simple.
我个人做的事情很简单。
System: Windows 8.1 x86_64, Python x64 versions
系统:Windows 8.1 x86_64, Python x64版本。
- Install latest Python 3.x binaries and add the directory to path (i also register .py extensions to run with Python 3.x).
- 安装最新的Python 3。x二进制文件并将目录添加到path(我也注册了.py扩展以运行Python 3.x)。
- Install latest Python 2.x binaries (not registering extensions with it and not adding to path).
- 安装最新的Python 2。x二进制文件(不使用它注册扩展,不添加路径)。
It seems that Python 3.x provides backwards compatibility with Python 2.x if Python 2.x binaries are installed.
似乎是python3。x提供向后兼容Python 2。如果Python 2 x。x安装二进制文件。
Download the installers from the official Python website. After installing them as above, run Python 3 normally as you did. Now for the Python 2.x programs run them as such: py -2 [command]
.
从官方的Python网站下载安装程序。在安装它们之后,像您一样正常运行Python 3。现在来看python2。x程序运行它们:py -2[命令]。
Tested on multiple Python 2.x only programs.
在多个Python 2上测试。x程序。
#16
0
To install and run any version of Python in the same system follow my guide below.
要在同一系统中安装和运行任何版本的Python,请遵循下面的指南。
For example say you want to install Python 2.x and Python 3.x on the same Windows system.
例如,您希望安装Python 2。x和Python 3。x在同一个Windows系统上。
-
Install both of their binary releases anywhere you want.
在您想要的任何地方安装它们的二进制版本。
- When prompted do not register their file extensions and
- 当提示没有注册他们的文件扩展名和。
- do not add them automatically to the PATH environment variable
- 不要将它们自动添加到PATH环境变量中?
-
Running simply the command
python
the executable that is first met in PATH will be chosen for launch. In other words, add the Python directories manually. The one you add first will be selected when you typepython
. Consecutive python programs (increasing order that their directories are placed in PATH) will be chosen like so:运行简单的命令python,在PATH中第一次遇到的可执行文件将被选择用于启动。换句话说,手动添加Python目录。您首先添加的一个将在您输入python时被选中。连续的python程序(增加其目录被放置在路径中的顺序)将被选择如下:
- py -2 for the second
python
- 第二个python的py -2。
- py -3 for the third
python
etc.. - 第三条python的py -3等等。
- py -2 for the second
-
No matter the order of "pythons" you can:
无论“蟒蛇”的顺序如何:
- run Python 2.x scripts using the command: py -2 (Python 3.x functionality) (ie. the first Python 2.x installation program found in your PATH will be selected)
- 运行Python 2。使用命令的x脚本:py -2 (Python 3)。x(即功能)。第一个Python 2。在您的路径中发现的x安装程序将被选中)
- run Python 3.x scripts using the command: or py -3 (ie. the first Python 3.x installation program found in your PATH will be selected)
- 运行Python 3。使用该命令的x脚本:或py -3 (ie)。第一个Python 3。在您的路径中发现的x安装程序将被选中)
In my example I have Python 2.7.14 installed first and Python 3.5.3. This is how my PATH variable starts with:
在我的例子中,我安装了Python 2.7.14和Python 3.5.3。我的路径变量就是这样开始的:
PATH=C:\Program Files\Microsoft MPI\Bin\;C:\Python27;C:\Program Files\Python_3.6\Scripts\;C:\Program Files\Python_3.6\;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Common Files\Intel\Shared
C:\程序文件\Python_3.6\脚本\;C:\程序文件\Python_3.6\;C:\ \ \ \ \ \ \ \ \ \ \ \ \, \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \
...
…
Note that Python 2.7 is first and Python 3.5 second.
请注意,Python 2.7是第一个,Python是3.5秒。
- So running
python
command will launch python 2.7 (if Python 3.5 the same command would launch Python 3.5). - 因此运行python命令将启动python 2.7(如果python 3.5相同的命令将启动python 3.5)。
- Running
py -2
launches Python 2.7 (because it happens that the second Python is Python 3.5 which is incompatible withpy -2
). Runningpy -3
launches Python 3.5 (because it's Python 3.x) - 运行py -2启动Python 2.7(因为第二个Python是Python 3.5,它与py -2不兼容)。运行py -3启动Python 3.5(因为它是Python 3.x)
- If you had another python later in your path you would launch like so:
py -4
. This may change if/when Python version 4 is released. - 如果在以后的路径中有另一条python,就会像这样启动:py -4。当Python版本4发布时,这可能会改变。
Now py -4
or py -5
etc. on my system outputs: Requested Python version (4) not installed
or Requested Python version (5) not installed
etc.
在我的系统输出中,py -4或py -5等等:请求的Python版本(4)没有安装或请求Python版本(5)没有安装等等。
Hopefully this is clear enough.
希望这已经足够清楚了。
#17
-1
If you can't get anything else to work, open an interpreter in whichever version you choose (I prefer using iPython) and:
如果您无法获得其他工作,请在您选择的任何版本中打开解释器(我更喜欢使用iPython),并且:
import subprocess
subprocess.call('python script.py -flags')
This uses whichever python version you are currently operating under. Works fine for a single script, but will quickly get out of hand if there are lots of scripts you run, in which case you can always make a batch file with all of these calls inside. Not the most elegant answer, but it works.
这将使用当前正在运行的python版本。对于单个脚本来说,它的工作很好,但是如果您运行的脚本很多,那么很快就会失去控制,在这种情况下,您总是可以在其中创建一个包含所有这些调用的批处理文件。不是最优雅的答案,但它确实有效。
Is there a way to make aliases for different python version a la Linux?
有没有一种方法可以为不同的python版本的la Linux做别名?
#18
-1
Only Works if your running your code in your Python IDE
只有在您的Python IDE中运行您的代码时才有用。
I have both Python 2.7 and Python 3.3 installed on my windows operating system. If I try to launch a file, it will usually open up on the python 2.7 IDE. How I solved this issue, was when I choose to run my code on python 3.3, I open up python 3.3 IDLE(Python GUI), select file, open my file with the IDLE and save it. Then when I run my code, it runs to the IDLE that I currently opened it with. It works vice versa with 2.7.
我在windows操作系统上安装了Python 2.7和Python 3.3。如果我尝试启动一个文件,它通常会打开python 2.7 IDE。我是如何解决这个问题的,当我选择在python3.3上运行我的代码时,我打开了python 3.3 IDLE(python GUI),选择file,打开我的文件并保存它。然后,当我运行我的代码时,它会运行到我当前打开它的空闲状态。反之亦然。
#19
-1
I have installed both python 2.7.13 and python 3.6.1 on windows 10pro and I was getting the same "Fatal error" when I tried pip2 or pip3.
我在windows 10pro上安装了python 2.7.13和python 3.6.1,当我尝试pip2或pip3时,我得到了同样的“致命错误”。
What I did to correct this was to go to the location of python.exe for python 2 and python 3 files and create a copy of each, I then renamed each copy to python2.exe and python3.exe depending on the python version in the installation folder. I therefore had in each python installation folder both a python.exe file and a python2.exe or python3.exe depending on the python version.
我所做的就是去到python的位置。为python2和python 3文件执行exe,并创建一个副本,然后将每个副本重命名为python2。exe和python3。exe取决于安装文件夹中的python版本。因此,我在每个python安装文件夹中都有python。exe文件和python2。exe或python3。exe取决于python版本。
This resolved my problem when I typed either pip2 or pip3.
当我键入pip2或pip3时,这就解决了我的问题。
#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启动程序。
#2
50
What I did was download both 2.7.6 and 3.3.4. Python 3.3.4 has the option to add the path to it in the environment variable so that was done. So basically I just manually added Python 2.7.6.
我所做的是下载2.7.6和3.3.4。Python 3.3.4可以选择将路径添加到环境变量中,这样就完成了。所以基本上我只是手动添加了Python 2.7.6。
How to...
如何……
-
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;
将C:\ Python27;所以你应该有两条路径到这两个版本的Python,但是如果你不这样做的话,你可以很容易地编辑它,这样你就可以做了。C:\ Python27;C:\ Python33;
-
Navigate to the Python27 folder in C:\ and change python.exe to python2.exe
导航到C:\和更改python中的Python27文件夹。exe,python2.exe
-
Navigate to the Python34 folder in C:\ and change python.exe to python3.exe
导航到C:\和更改python中的Python34文件夹。exe,python3.exe
-
Test: open up commmand prompt and type python2 ....BOOM! Python 2.7.6. exit out.
测试:打开commmand提示和类型python2 ....繁荣!Python 2.7.6。退出了。
-
Test: open up commmand prompt and type python3 ....BOOM! Python 3.4.3. exit out.
测试:打开commmand提示和类型python3 ....繁荣!Python 3.4.3。退出了。
Note: (to not break pip commands before following step 4 and 5 keep copy of python.exe in the same directory and renamed file)
注意:(在第4步和第5步保持python拷贝之前,不要破坏pip命令)。在同一个目录中,并重命名文件)
#3
44
I have multiple versions in windows. I just change the exe name of the version I'm not defaulting to.
我在windows中有多个版本。我只是更改了我不默认的版本的exe名称。
python.exe --> python26.exe
python。exe - - > python26.exe
pythonw.exe --> pythonw26.exe
pythonw。exe - - > pythonw26.exe
As for package installers, most exe installers allow you to choose the python install to add the package too. For manual installation check out the --prefix option to define where the package should be installed:
对于包安装程序,大多数exe安装程序允许您选择python安装来添加包。手动安装检查——前缀选项,以定义应该安装包的位置:
http://docs.python.org/install/index.html#alternate-installation-windows-the-prefix-scheme
http://docs.python.org/install/index.html alternate-installation-windows-the-prefix-scheme
#4
22
If you use Anaconda Python, you can easily install various environments.
如果您使用Anaconda Python,您可以轻松地安装各种环境。
Say you had Anaconda Python 2.7 installed and you wanted a python 3.4 environment:
假设您已经安装了Anaconda Python 2.7,您想要一个Python 3.4环境:
conda create -n py34 python=3.4 anaconda
Then to activate the environment:
然后激活环境:
activate py34
And to deactive:
和不激活:
deactivate py34
(With Linux, you should use source activate py34
.)
(使用Linux,您应该使用source activate py34。)
Links:
链接:
下载Python蟒蛇
说明环境
#5
6
Starting version 3.3 Windows version has Python launcher, please take a look at section 3.4. Python Launcher for Windows
开始版本3.3 Windows版本有Python启动器,请查看第3.4节。Python启动Windows
#6
5
Here's what you can do:
以下是你能做的:
Install cmder. Open and use Cmder as you would with you cmd terminal. Use the command alias to create command aliases.
安装cmd。像你和cmd终端一样打开和使用Cmder。使用命令别名创建命令别名。
I did the following:
我做了以下几点:
alias python2 = c:\python27\python.exe
alias python3 = c:\python34\python.exe
And that's it! ;-)
这是它!:-)
#7
3
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.
您可以安装Python one machine的多个版本,在安装过程中,您可以选择让其中之一与Python文件扩展相关联。如果您安装了模块,将会有不同版本的不同安装包,或者您可以选择您想要攻击的版本。由于它们通常安装在解释器版本的站点包目录中,所以不应该有任何冲突(但我没有测试过这个)。要选择python的哪个版本,如果不是默认的解释器,则必须手动指定解释器的路径。据我所知,它们将共享相同的路径和PYTHONPATH变量,这可能是一个问题。
Note: I run Windows XP. I have no idea if any of this changes for other versions, but I don't see any reason that it would.
注意:我运行Windows XP。我不知道其他版本是否有这种变化,但我看不出有什么原因。
#8
2
What I have done on my own windows computer where I have Python 2.7 and Python 3.4 installed is I wrote a simple .bat file in the same directory as my Python.exe files. They look something like,
我在自己的windows电脑上所做的是,我在那里安装了Python 2.7和Python 3.4,我在同一个目录下编写了一个简单的.bat文件,就像我的Python一样。exe文件。他们看起来像,
cmd /k "c:\python27\python.exe" %*
The %* allows you to add arguments (Python files) afterwards. I believe /k keeps the prompt open after it finishes running the script. Then I save that as python27.bat Then I go to my Python 3 directory and make a bat file there. Now in my command line I can write
%*允许您在之后添加参数(Python文件)。我相信/k在运行脚本后保持提示打开。然后我把它保存为python27。然后我转到Python 3目录,在那里做一个bat文件。现在在我的命令行中,我可以写。
Python27 helloworld.py
Or
或
Python34 helloworld.py
And they will run in their respective versions of Python. Make sure that c:\python27 and c:\python34 are in your environment variables.
它们将在各自版本的Python中运行。确保c:\python27和c:\python34在您的环境变量中。
I got my answer from here
我从这里得到了答案。
#9
2
I did this in three steps by following the instructions here: This is all taken directly from here: http://ipython.readthedocs.io/en/stable/install/kernel_install.html. I'm currently running Python 2.x on Windows 8 and have Anaconda 4.2.13 installed.
我按照这里的说明进行了三个步骤:这都是直接从这里得到的:http://ipyth.readthedocs.io/en/stable/install/kernel_install.html。我现在运行的是python2。在Windows 8上安装了Anaconda 4.2.13。
1) First install the latest version of python:
1)首先安装最新版本的python:
conda create -n python3 python=3 ipykernel
2) Next activate python3
2)下一个激活python3
activate python3
3) Install the kernel:
3)安装内核:
python -m ipykernel install --user
If you have Python 3 installed and want to install 2, switch the 2 and the 3 above. When you open a new notebook, you can now choose between Python 2 or 3.
如果您安装了Python 3,并希望安装2,请将上面的2和3切换。当你打开一个新笔记本时,你现在可以在Python 2或3中选择。
#10
1
Check your system environment variables after installing Python, python 3's directories should be first in your PATH variable, then python 2.
在安装Python之后检查系统环境变量,Python 3的目录应该首先在PATH变量中,然后是python2。
Whichever path variable matches first is the one Windows uses.
无论哪一个路径变量匹配首先是一个窗口使用。
As always py -2 will launch python2 in this scenario.
通常py -2会在这个场景中启动python2。
#11
1
I actually just thought of an interesting solution. While Windows will not allow you to easily alias programs, you can instead create renamed batch files that will call the current program.
我只是想到了一个有趣的解决方案。虽然Windows不会允许您轻松地使用别名程序,但是您可以创建重命名的批处理文件,它将调用当前程序。
Instead of renaming the executable which will break a lot of thing including pip, create the file python2.bat in the same directory as the python2.exe. Then add the following line:
不要重命名可执行文件,它会破坏很多东西,包括pip,创建文件python2。bat在与python2.exe相同的目录中。然后添加以下一行:
%~dp0python %*
What does this archaic syntax mean? Well, it's a batch script, (Windows version of bash). %~dp0 gets the current directory and %* will just pass all the arguments to python that were passed to the script.
这个古老的语法是什么意思?这是一个批处理脚本(bash的Windows版本)。%~dp0得到当前目录,%*将把所有参数传递给脚本。
Repeat for python3.bat
重复做python3.bat
You can also do the same for pip and other utilities, just replace the word python in the file with pip or whathever the filename. The alias will be whatever the file is named.
您也可以对pip和其他实用程序执行相同的操作,只需在文件中以pip或whathever文件名替换python。该别名将是该文件的名称。
Best of all, when added to the PATH, Windows ignores the extension so running
最重要的是,当添加到路径时,Windows忽略了扩展,因此运行。
python3
Will launch the python3 version and and the command python2 will launch the python2 version.
将启动python3版本,命令python2将启动python2版本。
BTW, this is the same technique Spyder uses to add itself to the path on Windows. :)
顺便说一下,这是Spyder用来在Windows上添加自己的技术。:)
#12
1
I have encountered that problem myself and I made my launchers in a .bat so you could choose the version you want to launch.
我自己也遇到过这个问题,我把我的发射器放进了一个。bat,这样你就可以选择你想要发射的版本了。
The only problem is your .py must be in the python folder, but anyway here is the code:
唯一的问题是你的。py必须在python文件夹中,但是这里是代码:
For Python2
对于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
For Python3
对于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
Save them as .bat and follow the instructions inside.
将它们保存为。bat,并按照里面的说明操作。
#13
0
Install the one you use most (3.3 in my case) over the top of the other. That'll force IDLE to use the one you want.
在我的例子中,安装你最常用的一个(在我的例子中是3.3)。这将迫使IDLE使用你想要的那个。
Alternatively (from the python3.3 README):
或者(从python3.3 README):
Installing multiple versions
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".
在Unix和Mac系统上,如果您打算使用相同的安装前缀(——前缀参数到configure脚本)安装多个版本的Python,那么您必须注意,您的主Python可执行文件并没有被安装不同版本所覆盖。使用“make altinstall”安装的所有文件和目录都包含主要和次要版本,因此可以并排共存。“make install”还可以创建${前缀}/bin/python3,这是指${前缀}/bin/pythonX.Y。如果您打算使用相同的前缀安装多个版本,则必须决定哪个版本(如果有的话)是您的“主要”版本。使用“make Install”安装该版本。使用“make altinstall”安装所有其他版本。
For example, if you want to install Python 2.6, 2.7 and 3.3 with 2.7 being the primary version, you would execute "make install" in your 2.7 build directory and "make altinstall" in the others.
例如,如果您希望安装Python 2.6、2.7和3.3,其中2.7是主要版本,那么您将在2.7构建目录中执行“make install”,在其他版本中“make altinstall”。
#14
0
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.
我只需要安装它们。然后我使用了*(便携式)在http://defaultprogramseditor.com/上软下“文件类型设置”/“上下文菜单”搜索:“py”,选择. py文件并添加一个“打开”命令2闲置通过复制existant命令的名为“开放与闲置,改变名字空闲3.4.1/2.7.8,和remplacing文件数量的各自版本的程序路径。现在,我只需右键单击.py文件并选择要使用的空闲文件。如果你喜欢,也可以直接翻译。
#15
0
What i have done personally is very simple.
我个人做的事情很简单。
System: Windows 8.1 x86_64, Python x64 versions
系统:Windows 8.1 x86_64, Python x64版本。
- Install latest Python 3.x binaries and add the directory to path (i also register .py extensions to run with Python 3.x).
- 安装最新的Python 3。x二进制文件并将目录添加到path(我也注册了.py扩展以运行Python 3.x)。
- Install latest Python 2.x binaries (not registering extensions with it and not adding to path).
- 安装最新的Python 2。x二进制文件(不使用它注册扩展,不添加路径)。
It seems that Python 3.x provides backwards compatibility with Python 2.x if Python 2.x binaries are installed.
似乎是python3。x提供向后兼容Python 2。如果Python 2 x。x安装二进制文件。
Download the installers from the official Python website. After installing them as above, run Python 3 normally as you did. Now for the Python 2.x programs run them as such: py -2 [command]
.
从官方的Python网站下载安装程序。在安装它们之后,像您一样正常运行Python 3。现在来看python2。x程序运行它们:py -2[命令]。
Tested on multiple Python 2.x only programs.
在多个Python 2上测试。x程序。
#16
0
To install and run any version of Python in the same system follow my guide below.
要在同一系统中安装和运行任何版本的Python,请遵循下面的指南。
For example say you want to install Python 2.x and Python 3.x on the same Windows system.
例如,您希望安装Python 2。x和Python 3。x在同一个Windows系统上。
-
Install both of their binary releases anywhere you want.
在您想要的任何地方安装它们的二进制版本。
- When prompted do not register their file extensions and
- 当提示没有注册他们的文件扩展名和。
- do not add them automatically to the PATH environment variable
- 不要将它们自动添加到PATH环境变量中?
-
Running simply the command
python
the executable that is first met in PATH will be chosen for launch. In other words, add the Python directories manually. The one you add first will be selected when you typepython
. Consecutive python programs (increasing order that their directories are placed in PATH) will be chosen like so:运行简单的命令python,在PATH中第一次遇到的可执行文件将被选择用于启动。换句话说,手动添加Python目录。您首先添加的一个将在您输入python时被选中。连续的python程序(增加其目录被放置在路径中的顺序)将被选择如下:
- py -2 for the second
python
- 第二个python的py -2。
- py -3 for the third
python
etc.. - 第三条python的py -3等等。
- py -2 for the second
-
No matter the order of "pythons" you can:
无论“蟒蛇”的顺序如何:
- run Python 2.x scripts using the command: py -2 (Python 3.x functionality) (ie. the first Python 2.x installation program found in your PATH will be selected)
- 运行Python 2。使用命令的x脚本:py -2 (Python 3)。x(即功能)。第一个Python 2。在您的路径中发现的x安装程序将被选中)
- run Python 3.x scripts using the command: or py -3 (ie. the first Python 3.x installation program found in your PATH will be selected)
- 运行Python 3。使用该命令的x脚本:或py -3 (ie)。第一个Python 3。在您的路径中发现的x安装程序将被选中)
In my example I have Python 2.7.14 installed first and Python 3.5.3. This is how my PATH variable starts with:
在我的例子中,我安装了Python 2.7.14和Python 3.5.3。我的路径变量就是这样开始的:
PATH=C:\Program Files\Microsoft MPI\Bin\;C:\Python27;C:\Program Files\Python_3.6\Scripts\;C:\Program Files\Python_3.6\;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Common Files\Intel\Shared
C:\程序文件\Python_3.6\脚本\;C:\程序文件\Python_3.6\;C:\ \ \ \ \ \ \ \ \ \ \ \ \, \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \
...
…
Note that Python 2.7 is first and Python 3.5 second.
请注意,Python 2.7是第一个,Python是3.5秒。
- So running
python
command will launch python 2.7 (if Python 3.5 the same command would launch Python 3.5). - 因此运行python命令将启动python 2.7(如果python 3.5相同的命令将启动python 3.5)。
- Running
py -2
launches Python 2.7 (because it happens that the second Python is Python 3.5 which is incompatible withpy -2
). Runningpy -3
launches Python 3.5 (because it's Python 3.x) - 运行py -2启动Python 2.7(因为第二个Python是Python 3.5,它与py -2不兼容)。运行py -3启动Python 3.5(因为它是Python 3.x)
- If you had another python later in your path you would launch like so:
py -4
. This may change if/when Python version 4 is released. - 如果在以后的路径中有另一条python,就会像这样启动:py -4。当Python版本4发布时,这可能会改变。
Now py -4
or py -5
etc. on my system outputs: Requested Python version (4) not installed
or Requested Python version (5) not installed
etc.
在我的系统输出中,py -4或py -5等等:请求的Python版本(4)没有安装或请求Python版本(5)没有安装等等。
Hopefully this is clear enough.
希望这已经足够清楚了。
#17
-1
If you can't get anything else to work, open an interpreter in whichever version you choose (I prefer using iPython) and:
如果您无法获得其他工作,请在您选择的任何版本中打开解释器(我更喜欢使用iPython),并且:
import subprocess
subprocess.call('python script.py -flags')
This uses whichever python version you are currently operating under. Works fine for a single script, but will quickly get out of hand if there are lots of scripts you run, in which case you can always make a batch file with all of these calls inside. Not the most elegant answer, but it works.
这将使用当前正在运行的python版本。对于单个脚本来说,它的工作很好,但是如果您运行的脚本很多,那么很快就会失去控制,在这种情况下,您总是可以在其中创建一个包含所有这些调用的批处理文件。不是最优雅的答案,但它确实有效。
Is there a way to make aliases for different python version a la Linux?
有没有一种方法可以为不同的python版本的la Linux做别名?
#18
-1
Only Works if your running your code in your Python IDE
只有在您的Python IDE中运行您的代码时才有用。
I have both Python 2.7 and Python 3.3 installed on my windows operating system. If I try to launch a file, it will usually open up on the python 2.7 IDE. How I solved this issue, was when I choose to run my code on python 3.3, I open up python 3.3 IDLE(Python GUI), select file, open my file with the IDLE and save it. Then when I run my code, it runs to the IDLE that I currently opened it with. It works vice versa with 2.7.
我在windows操作系统上安装了Python 2.7和Python 3.3。如果我尝试启动一个文件,它通常会打开python 2.7 IDE。我是如何解决这个问题的,当我选择在python3.3上运行我的代码时,我打开了python 3.3 IDLE(python GUI),选择file,打开我的文件并保存它。然后,当我运行我的代码时,它会运行到我当前打开它的空闲状态。反之亦然。
#19
-1
I have installed both python 2.7.13 and python 3.6.1 on windows 10pro and I was getting the same "Fatal error" when I tried pip2 or pip3.
我在windows 10pro上安装了python 2.7.13和python 3.6.1,当我尝试pip2或pip3时,我得到了同样的“致命错误”。
What I did to correct this was to go to the location of python.exe for python 2 and python 3 files and create a copy of each, I then renamed each copy to python2.exe and python3.exe depending on the python version in the installation folder. I therefore had in each python installation folder both a python.exe file and a python2.exe or python3.exe depending on the python version.
我所做的就是去到python的位置。为python2和python 3文件执行exe,并创建一个副本,然后将每个副本重命名为python2。exe和python3。exe取决于安装文件夹中的python版本。因此,我在每个python安装文件夹中都有python。exe文件和python2。exe或python3。exe取决于python版本。
This resolved my problem when I typed either pip2 or pip3.
当我键入pip2或pip3时,这就解决了我的问题。