I'm running Windows 7 64-bit with Python 3.4.1, 64-bit cmd window I've appended the PATH in system Environment Variable with ;C:\Python34 and saved, then gone into cmd and done the following, yet I keep getting an 'INVALID SYNTAX' message. Yes, I've searched the Q&A here and seen several threads with same problem, but haven't reached success trying their suggestions. As can be seen, I've tried 3 variations of the basic command "python ." Please help.
-
1you're already inside the python shell. you don't try to RE-EXECUTE python. and pictures of problems are not acceptable. none of what's in there couldn't be copy/pasted here as text. – Marc B Jul 06 '16 at 21:18
3 Answers
I think you're misunderstanding the idea.
If you want to execute a script "RUN_ME.py", run python RUN_ME.py
directly in the command line. (type cmd
into start and then python RUN_ME.py
in the window you get)
If you want to type some lines of python and interpret them directly, type python
without arguments. (or use the program shortcut you used here)

- 1,085
- 7
- 16
-
Note that pycharm, atom, etc. do this stuff for you automatically. – Work of Artiz Jul 06 '16 at 21:24
-
So, where I typed python RUN_ME.py after the line os.chdir(...) is incorrect? It seems I did exactly what you're stating to do. – CB001 Jul 07 '16 at 14:28
The mistake made here is the difference between the command line and the python REPL.
When you opened the terminal the way you did, probably by clicking on python terminal
or whatever, you opened the python REPL (also available by executing python
without arguments in command line), this is a place where you can execute code directly (no scripts). it used to be able to run python scripts as well but the command was phased out in python 3.x. Typically the REPL starts lines with >>>
To run a python script, you have to be in the command line and give the script as parameter to python, aka
python <script_name>
. Getting the command line on windows can be done directly by typing cmd, or if you want to open it at a certain path, browse to the path you want in the file explorer and type cmd
into the place where the path is displayed.

- 1,085
- 7
- 16
Okay, I understand now not to use 'python' plus the .py filename when already in the Python '>>>' prompt. Here's a simple try within Windows command prompt at navigating to the directory where the 'RUN_ME.py' file is located and attempting to run:
C:\>cd program files\trader workstation
C:\Program Files\Trader Workstation>cd ibridgepy
C:\Program Files\Trader Workstation\IBridgePy>python
Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:45:13) [MSC v.1600 64 bit (AM D64)] on win32 Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.getcwd()
'C:\\Program Files\\Trader Workstation\\IBridgePy'
>>> RUN_ME.py
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'RUN_ME' is not defined

- 21
- 1
- 1
- 4