0

I am trying to run python from the powershell, I go to the python directory using

cd f:\python27

If i type python i get the following error (despite it being a exe file in the folder):

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
Suggestion [3,General]: The command python was not found, but does exist in the 
current location. Windows PowerShell does not load commands from the current 
location by default. If you trust this command, instead type: ".\python". See "get-
help about_Command_Precedence" for more details.

If I type .\python it just does nothing and returns the prompt again. I created a simple file called helloworld.py in a text editor and saved it into the python27 directory, which contains one line:

print "Hello World!"

and I tried typing both

python helloworld.py
.\python helloworld.py

The first returns the original error and the second returns the prompt again without apparently doing anything, I cant get the python program to run. I am new to Powershell and Pyton and I am trying to work my way through learn python the hard way, can anyone help or point where I am going wrong and explain what it is I am doing wrong and what the solution is? thanks

cicada84
  • 1
  • 1
  • 2
  • 1
    Possible duplicate of [Running Python in PowerShell?](https://stackoverflow.com/questions/19676403/running-python-in-powershell) - and several others. – kabanus Jul 23 '18 at 19:58

2 Answers2

1

You should be able to get it working by telling Powershell where to find Python. This can be done by setting an Environment Variable.

Open Powershell as an admin. Run this code:

[Environment]::SetEnvironmentVariable("Path", "$env:Path;C:\Program Files\Python35-32")

Note: Here, in Path, add the path where you’ve installed Python in your system, here in my case it is “C:\Program Files\Python35-32”.

This should help with the issue.
To thest, try running:

python --version

It should display the version number of Python installed in the system, this is what it showed in my system:

“Python 3.5.1″

  • I did this, and now the python command just returns the prompt, like it did when I type ./python before. – cicada84 Jul 23 '18 at 20:24
  • Also python --version also just returns the powershell prompt again too – cicada84 Jul 23 '18 at 20:24
  • This sounds odd. When Powershell just returns to the promt it means it has run successfully. Maybe you have some weird bug or there is something odd with your python installation. Have you tried rebooting your machine? Else I would recommend re-installing python. – Henrik Stanley Mortensen Jul 23 '18 at 20:43
  • 1
    thank you @Henrik Stanley Mortensen reinstalling python worked – cicada84 Jul 25 '18 at 09:24
0

I've not figured this out myself but as a workaround, either run

cmd /C python helloworld.py

or

python helloworld.py COMMAND_LINE_ARGUMENTS