syntax error when using command line in python

Johanna picture Johanna · Dec 19, 2012 · Viewed 223.8k times · Source

I am a beginner to python and am at the moment having trouble using the command line. I have a script test.py (which only contains print("Hello.")), and it is located in the map C:\Python27. In my system variables, I have specified python to be C:\Python27 (I have other versions of Python installed on my computer as well).

I thought this should be enough to run python test.py in the command line, but when I do so I get this:

File "<stdin>", line 1
python test.py
       ^
SyntaxError: invalid syntax

What is wrong? Thanks in advance!

Answer

jdotjdot picture jdotjdot · Dec 19, 2012

Looks like your problem is that you are trying to run python test.py from within the Python interpreter, which is why you're seeing that traceback.

Make sure you're out of the interpreter, then run the python test.py command from bash or command prompt or whatever.