I'm trying to follow Zed Shaw's guide for Learning Python the Hard Way. I need to use python in Powershell. I have Python 2.7.3 installed in C:\Python27
. Whenever I type python into Powershell, I get an error that says the term 'python' is not recognized as the name of a cmdlet, function, script file, or operable program. I also typed in this: [Environment]::SetEnvironmentVariable("Path", "$env:Path;C:\Python27", "User")
That was a suggested solution provided, but typing python into Powershell still does nothing. I can type in "start python" and it opens up a window with python but I need it in Powershell. Thanks.
With your PowerShell command line open, enter python to run the Python 3 interpreter. (Some instructions prefer to use the command py or python3 , these should also work).
Sometimes you install Python on Windows and it doesn't configure the path correctly. Make sure you enter [Environment]::SetEnvironmentVariable("Path", "$env:Path;C:\Python27", "User") in PowerShell to configure it correctly. You also have to either restart PowerShell or your whole computer to get it to really be fixed.
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 ...
CTRL + Z, then hit ENTER to exit python from powershell.
Try setting the path this way:
$env:path="$env:Path;C:\Python27"
For what's worth, this command did it for me (Python3.3) :
[System.Environment]::SetEnvironmentVariable("PATH", $Env:Path + ";C:\Python33", "Machine")
I just had to restart the Powershell after that.
$env:path="$env:Path;C:\Python27"
will only set it for the current session. Next time you open Powershell, you will have to do the same thing again.
The [Environment]::SetEnvironmentVariable()
is the right way, and it would have set your PATH environment variable permanently. You just have to start Powershell again to see the effect in this case.
The Directory is not set correctly so Please follow these steps.
In the "Variable value" box, Make sure you see following:
;c:\python27\;c:\python27\scripts
Click "OK", Test this change by restarting your windows powershell. Type
python
Now python version 2 runs! yay!
For a permanent solution I found the following worked:
[Environment]::SetEnvironmentVariable("Path", "$env:Path;C:\Python 3.5")
This works for me permanently:
[Environment]::SetEnvironmentVariable("Path", "$env:Path;C:\Python27","User")
From the Python Guide, this is what worked for me (Python 2.7.9):
[Environment]::SetEnvironmentVariable("Path", "$env:Path;C:\Python27\;C:\Python27\Scripts\", "User")
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