Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell Python: Change version used

I'm using windows xp.

I'm trying to use Python in powershell. On my computer I have both Python 3.3 and 2.7 installed. I'm trying to run 2.7 but whenever I type "python" into powershell it opens 3.3.

How do I select the version of Python to run?

like image 395
The Guy Avatar asked Nov 11 '12 03:11

The Guy


People also ask

How do I change Python version in PowerShell?

make a batch file to launch it called python. bat in a folder in the PATH ahead of other versions. make an alias (in your PS Profile) named python to launch the one you want ( New-Alias -name python -Value C:\Python27\python.exe , etc).

How do I make Python 3.10 default Windows?

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.

How do I change Python version from command line?

The default Python interpreter is referenced on Windows using the command py. Using the Command Prompt, you can use the -V option to print out the version. You can also specify the version of Python you'd like to run. For Windows, you can just provide an option like -2.7 to run version 2.7.


Video Answer


2 Answers

In powershell, enter the following:

$Env:PY_PYTHON = 2

Then try using the command "py". It should start up Python 2.7. If you ever want to run Python 3.3 again, "py -3" will do the trick.

like image 176
ChimeraObscura Avatar answered Sep 29 '22 19:09

ChimeraObscura


Something like Python Select? Windows support is experimental but it might be worth a try.

https://github.com/Activestate/pythonselect

There's also switchpy, although that only supports up to Python 3.2.

apipes.blogspot.com/2010/10/switchpy.html?m=1

like image 43
Talvalin Avatar answered Sep 29 '22 19:09

Talvalin