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

I have both Python 2.7 and 3.4 installed on my Windows machine. When I write Python in CMD it uses Python2.7 by default. How do I switch to 3.4?

+3


source to share


3 answers


You will need to make changes to your PATH environment variable. To do this, click the Start button, right-click Computer, click Properties, click Advanced System Settings in the left sidebar. Then click the Environmental Variables button.

In the "User or System Variables" section, the "PATH" variable will be listed, which includes the path to the Python installation. You can change this to the Python 3 install path.



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. Then you can use both 2 and 3 by calling python

and python3

respectively.

+3


source


Create two batch files, python2.bat

and python3.bat

. Let each batch file add the corresponding Python directory to the path and then run python.exe

.

eg. Python2.bat:



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

      

+3


source


Simply changing the name of python.exe to everything (ex: pytoioion.exe) in C: / Python34 or C: / Python27 will switch between the two versions. To test run this on command line

C: Users / (your_name)> python

+1


source







All Articles