Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I'm trying to use python in powershell

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.

like image 377
masonc15 Avatar asked Aug 05 '12 02:08

masonc15


People also ask

Can I use Python in PowerShell?

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).

How do I get python to recognize in PowerShell?

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.

Why can't PowerShell find Python?

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 ...

How do I get out of python PowerShell?

CTRL + Z, then hit ENTER to exit python from powershell.


7 Answers

Try setting the path this way:

 $env:path="$env:Path;C:\Python27" 
like image 103
Mike Shepard Avatar answered Sep 29 '22 16:09

Mike Shepard


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.

like image 38
Matthieu Riegler Avatar answered Sep 29 '22 16:09

Matthieu Riegler


$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.

like image 28
manojlds Avatar answered Sep 29 '22 15:09

manojlds


The Directory is not set correctly so Please follow these steps.

  1. "MyComputer">Right Click>Properties>"System Properties">"Advanced" tab
  2. "Environment Variables">"Path">"Edit"
  3. In the "Variable value" box, Make sure you see following:

    ;c:\python27\;c:\python27\scripts

  4. Click "OK", Test this change by restarting your windows powershell. Type

    python

  5. Now python version 2 runs! yay!

like image 29
HeggyHere Avatar answered Sep 29 '22 16:09

HeggyHere


For a permanent solution I found the following worked:

[Environment]::SetEnvironmentVariable("Path", "$env:Path;C:\Python 3.5")
like image 43
Matt Avatar answered Sep 29 '22 14:09

Matt


This works for me permanently:

[Environment]::SetEnvironmentVariable("Path", "$env:Path;C:\Python27","User")

like image 37
Dr. José Manuel Gilpérez Avatar answered Sep 29 '22 14:09

Dr. José Manuel Gilpérez


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")

like image 28
datalifenyc Avatar answered Sep 29 '22 15:09

datalifenyc