Why is 'python' not recognized in powershell?

Question:

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:Userslenovo> 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:UserslenovoAppDataLocalProgramsPythonPython36") 

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.

Asked By: Gautam J

||

Answers:

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:UserslenovoAppDataLocalProgramsPythonPython36

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.

Answered By: cosmic_inquiry

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

Check out the image to see how it worked.

Answered By: user10528475

Check out your config path

Maybe look like : C:UserslenovoAppDataLocalProgramsPythonPython36

Change it to : C:UserslenovoAppDataLocalProgramsPythonPython36

Answered By: Hảo Nguyễn

I just had the same issue, posting for anyone who has this issue in the future.

The solution was to go to ‘Manage App Execution Aliases’ and turn off ‘App Installer’ for python.

For me it was in there twice, once for python.exe and once for python3.exe. Basically that causes Windows Power Shell to launch into the app store instead of looking for environment variables when typing in python commands. Once you turn those off it’ll default to looking for environment variables instead and any ones that you have set will work again. Use cosmic_inquiry’s comment to set those paths if they aren’t already. For me they were already set so I was very confused but just turning off those switches fixed everything. Microsoft screwing up big time here.

Answered By: Avery17
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.