Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. When I type Python in CMD it defaults to Python2.7. How do I switch to 3.4?

like image 502
Ryan Miles Avatar asked Jan 10 '23 05:01

Ryan Miles


2 Answers

Create two batch files, python2.bat and python3.bat. Have each batch file add the appropriate Python directory to the path, then launch python.exe.

E.G. Python2.bat:

@echo off
set OLDPATH=%PATH%
path C:\Python27;%PATH%
python.exe
path %OLDPATH%
like image 127
Mark Ransom Avatar answered Jan 11 '23 17:01

Mark Ransom


You'll have to make changes to the PATH environmental variable. 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. 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.

like image 35
nanny Avatar answered Jan 11 '23 17:01

nanny