I am attempting to learn the very basics of Python using the guide "Learn Python the hard way" by Zed A. Shaw. The problem that I am having is that I can run Python scripts, but only when using .\
in front of the name. This opens up CMD for a split second and then closes.
If I attempt to run the file it returns that the file is not an operable program file, script, etc..
I've found multiple questions on Stack Overflow that relate to this question, but none of the solutions have worked for me.
Two things I've tried:
[Environment]::SetEnvironmentVariable("Path", "$env:Path;C:\Python27", "User")
and
$env:PATH =$env:PATH+";."
Source: (How do you remove the PowerShell requirement that scripts and executables be preceded by ".\"?)
When I check the environment variable PATH it has the correct path within it, so what other things could be causing this?
To run the Python Shell, open the command prompt or power shell on Windows and terminal window on mac, write python and press enter. A Python Prompt comprising of three greater-than symbols >>> appears, as shown below. Now, you can enter a single statement and get the result.
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).
Since, you are able to run Python in PowerShell. You can just do python <scriptName>.py
to run the script. So, for a script named test.py
containing
name = raw_input("Enter your name: ") print "Hello, " + name
The PowerShell session would be
PS C:\Python27> python test.py Enter your name: Monty Python Hello, Monty Python PS C:\Python27>
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