9

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.

3
  • See stackoverflow.com/questions/714877/… Commented Dec 14, 2017 at 4:15
  • @JohnGordon Thanks! But I don't understand the answers given. Could you give a simple answer?? ;-) Commented Dec 14, 2017 at 4:26
  • Make sure you specified you want the installer to add python to the env variables when installing it. If not, you can modify the installation, and mark the checkbox. This link shows details on to do achive it: c-sharpcorner.com/article/python-py-works-but-python-doesnt/…. Commented Nov 20, 2023 at 19:01

4 Answers 4

22

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

Check out the image to see how it worked.

Sign up to request clarification or add additional context in comments.

2 Comments

Why is it the case?
you can then also copy py.exe to python.exe in your Python\Launcher folder located in your user file under "AppData\Local\Programs\Python\Launcher"
15

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.

Comments

4

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.

1 Comment

This solved my error! Thank you, for those who can't find out how to Manage App Extension on Windows 11 ask chatgpt or cursor app and it will help you find out. Also scroll down a bit for an image verification (although it is in chinese)
3

Check out your config path

Maybe look like : C:\Users\lenovo\AppData\Local\Programs\Python\Python36\

Change it to : C:\Users\lenovo\AppData\Local\Programs\Python\Python36

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.