Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is 'python' not recognized in powershell?

I have installed python 3.6 in my Windows 10 PC. I also use Pycharm to make my scripts. It runs perfectly fine there. But my problem is I can't run python in powershell. I am told to simply type 'python' in powershell and it should automatically start python. But, I get an error saying it's not recognised.

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

PS C:\Users\lenovo> python
python : The term 'python' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ python
+ ~~~~~~
    + CategoryInfo          : ObjectNotFound: (python:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Some suggested to type this:

[Environment]::SetEnvironmentVariable("Path", "$enc:Path;C:\Users\lenovo\AppData\Local\Programs\Python\Python36") 

The path given in the above code is correct for my PC. Infact, Python runs after I give the above code. But, that is my problem. Every time I close and open powershell again, I have to type the above code to get python running. I tried typing this in Powershell running as an admin too. But, it doesn't work. I even tried restarting my PC, still the problem refuses to resolve.

I am expected to type the above code every time I want to run python in a new powershell window. This is a bit annoying. Any help would be appreciated. Thanks.

like image 404
Gautam J Avatar asked Dec 14 '17 04:12

Gautam J


People also ask

Why Python is not opening 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.

How do I enable 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). You will know that you're successful because a >>> prompt with three greater-than symbols will display.

How do I fix Python not recognized?

Specify the full location to python.exe One way to fix the error would be to launch Python from the Command Prompt by passing in the full path to the executable file each time you wanted to run Python. In other words, instead of typing Python you would type something like C:\Users\me\path\to\python.exe .


2 Answers

Or just simply type 'py' instead of 'python' in the PowerShell and hit enter.

Check out the image to see how it worked.

like image 98
user10528475 Avatar answered Sep 26 '22 08:09

user10528475


You need to add the path to your environment variables:

Control Panel>System and Security>System>Advanced System Settings>Environment Variables

Select edit PATH and append:

C:\Users\lenovo\AppData\Local\Programs\Python\Python36

to the path. Hit apply and ok. After closing and reopening the shell you should be able to type "python" and be in the python shell.

like image 34
cosmic_inquiry Avatar answered Sep 24 '22 08:09

cosmic_inquiry