I installed Python 2.6
and Python 3.1
on Windows 7 and set environment variable: path = d:\python2.6
.
When I run python
in cmd
, it displays the python version 2.6, which is what I want!
But, when I wrote a script in a bat file and ran it, the displayed python version was 3.1.
import sys
print (sys.version)
What's going on here?
This is if you have both the versions installed.
Go to This PC -> Right-click -> Click on Properties -> Advanced System Settings.
You will see the System Properties
. From here navigate to the "Advanced"
Tab -> Click on Environment Variables
.
You will see a top half for the user variables and the bottom half for System variables
.
Check the System Variables
and double-click on the Path
(to edit the Path).
Check for the path of Python(which you wish to run i.e. Python 2.x or 3.x) and move it to the top of the Path list.
Restart the Command Prompt, and now when you check the version of Python, it should correctly display the required version.