I have two Python versions on my machine (Windows Vista), 2.6 (located in C/Program files) and 2.7 (located in C/).
1- I open PowerShell
2- I type python, and it calls python 2.6.1.
3- I want to change the path for Python 2.7, so I type:
[Environment]::SetEnvironmentVariable("Path", "$env:Path;C:\Python27", "User")
4- and then when I run python again it still calls the version 2.6. and there is no way I can change it. I also tried to restart the computer after changing the path, with no success.
Any suggestions?
You can create a new user variable called Path , or append to the system one (so it'd affect all users). Add your Python27 directory there in the Path system variable (with a ; as a separator). You can swap them ( C:\Python26;C:\Python27 and C:\Python27;C:\Python26 ) to change the default one.
You can run python in cmd without typing its full path but can't do so in PowerShell is because PowerShell doesn't find the path of the .exe, you likely installed Python to C:\Program Files\Python39, and the folder is added to system path variable and NOT user path, then you must have run cmd as admin so it has access ...
Use $Env:PATH to Set the PATH Environment Variables in Windows PowerShell. Usually, we can set the PATH variable by navigating through the control panel of our operating system. However, inside Windows PowerShell, we can output all our file paths using the $Env:PATH environment variable.
You have to set the path in the Environment Variables settings so it would be kept after closing shell and/or reboot.
Computer (right-click) > Properties > Advanced System Settings > Environment Variables
You can create a new user variable called Path
, or append to the system one (so it'd affect all users).
Add your Python27 directory there in the Path
system variable (with a ;
as a separator). You can swap them (C:\Python26;C:\Python27
and C:\Python27;C:\Python26
) to change the default one.
Python 2.6.1 is already in your path as demonstrated by item number 2 in your list. On number 3, you're adding Python 2.7 to your path after Python 2.6.1's entry. You need to remove Python 2.6.1 from your environment variable, or at a minimum, set it so that 2.7 is listed first.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With