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.
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.
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.
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 .
Or just simply type 'py' instead of 'python' in the PowerShell and hit enter.
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.
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