First time trying to run python from Powershell. Am I using the right command/ what do I need to do to permit use of Python?

by ndettmer   Last Updated July 12, 2019 05:26 AM

I'm trying to run some Python files from command line, using PowerShell, but I'm really unfamiliar with the shell, and I've run into some issues trying to run python. I think there is some preparation process for python that I've missed, but I don't know what.

In trying to run Python through Powershell, I've tried installing Python 2.7 on my computer. While it changed the nature of the error message I was first receiving, it has otherwise not done much.

I've also tried doing some research to see what might be going wrong, personally, but I'm having some trouble finding an exact answer to my problem, and therefore figured I'd try asking, on here.

From what I've seen, online, I think this is the correct way to call and run a python file in Powershell. It's what I'm currently using:

PS C:\Users\nickd\documents\Coding\Comp_Sci_Class\Python\debugger> python

This should run a program that tests whether or not a debugger is working. Instead, I get the following error message when I try and use the command '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

As such, I'm led to believe that there is some step in preparing Python for use on Windows Powershell that I'm just missing, but I'm not finding a clean cut answer for what that might be.

Could somebody please help me out, and describe what it is I might need to do? I know that what I'm missing is likely extremely simple, and I apologize upfront if this is a silly problem to have. That said, if somebody could point me in the right direction as to what I need to do, I'd be really grateful.

Thank you.

Answers 3

Powershell doesn't find where you have installed python. If you add the folder where python.exe is located to path then it will work. See here

July 11, 2019 21:07 PM

You have to add location of Python.exe to your environment variable..

Your path might be C:\Program Files\Python27

Please follow the below steps :

1) Right Click on This PC (My Computer) and Select Properties ( Win Key + Pause key)
2) Click on Advance system setting from left pane
3) Click on Environment Variables...
4) select variable called "Path" from second list box
5) Click on Edit button below the same list box
6) Add python.exe full path ( do not include filename )
7) close all dialogs by clicking OK
8) restart your powershell | ISE

enter image description here

Niraj Gajjar
Niraj Gajjar
July 12, 2019 05:16 AM

Since Python 3.3, the PythonLauncher is installed with Python on Windows. It is py.exe and is already in the PATH (c:\windows).

Just run py If you have multiple versions of Python installed, py -3.6 (for example) will run Python 3.6.

Mark Tolonen
Mark Tolonen
July 12, 2019 05:25 AM

Related Questions

Updated February 03, 2018 06:26 AM

Updated May 06, 2017 00:26 AM

Updated August 07, 2018 16:26 PM

Updated October 31, 2017 09:26 AM

Updated December 25, 2018 11:26 AM