简体   繁体   English

在Windows CMD中更改Python 2.x和3.x?

[英]Changing between Python 2.x and 3.x in windows CMD?

I have both Python 2.7 and 3.4 installed on my Windows Machine. 我的Windows机器上安装了Python 2.7和3.4。 When I type Python in CMD it defaults to Python2.7. 当我在CMD中键入Python时,默认为Python2.7。 How do I switch to 3.4? 如何切换到3.4?

Create two batch files, python2.bat and python3.bat . 创建两个批处理文件python2.batpython3.bat Have each batch file add the appropriate Python directory to the path, then launch python.exe . 让每个批处理文件将相应的Python目录添加到路径中,然后启动python.exe

EG Python2.bat: EG Python2.bat:

@echo off
set OLDPATH=%PATH%
path C:\Python27;%PATH%
python.exe
path %OLDPATH%

You'll have to make changes to the PATH environmental variable. 您必须更改PATH环境变量。 To do this, click the Start button, right click on "Computer", hit "Properties", click "Advanced System Settings" in the left sidebar. 要执行此操作,请单击“开始”按钮,右键单击“计算机”,单击“属性”,然后单击左侧栏中的“高级系统设置”。 Then click the Environmental Variables button. 然后单击“环境变量”按钮。

Under User or System variables, there will be a variable called "PATH" that includes a path to you Python installation. 在User或System变量下,将有一个名为“PATH”的变量,其中包含Python安装的路径。 You can change this to the Python 3 install path. 您可以将其更改为Python 3安装路径。

You can also change the name of the Python 3 executable to "python3.exe", and add the directory to the path variable, separating it from other directories with a semicolon. 您还可以将Python 3可执行文件的名称更改为“python3.exe”,并将该目录添加到路径变量中,并使用分号将其与其他目录分开。 Then you can use both 2 and 3 by calling python and python3 respectively. 然后你可以分别通过调用pythonpython3来使用2和3。

Simply changing the name of the python.exe to anything (ex:pytoioion.exe) in your C:/Python34 or C:/Python27 will switch between the two versions. 只需将python.exe的名称更改为C:/ Python34或C:/ Python27中的任何内容(例如:pytoioion.exe),即可在两个版本之间切换。 To verify, run this on your command prompt 要进行验证,请在命令提示符下运行此命令

C:Users/(your_name)>python C:用户/(your_name)>蟒

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM