Executing modules as scripts tutorial doesn't work for me

6. Modules — Python 3.10.13 documentation, 6.1.1. Executing modules as scripts, doesn’t work for me. I get the following error:

python fibo.py 50
File “”, line 1
python fibo.py 50
^^^^
SyntaxError: invalid syntax

I’m using Python 3.10.5 (tags/v3.10.5:f377153, Jun 6 2022, 16:14:13) [MSC v.1929 64 bit (AMD64)] on win32 (Windows 10). Is it the tutorial or is the something wrong in my setup. Ive tried it several time and triple checked the code.

Please advise.

You don’t really say what you did, just that you checked it. The module script at the top of the chapter, plus the snippet in the section you mention, with the check that the current module name is __main__, all need to be in fibo.py; then you run that from a terminal window (cmd or PowerShell) prompt as indicated - although since you’re on Windows, that depends a bit on how things were installed and where they were installed from. If you have the Python Launcher installed, you probably want to run it as: py fibo.py 50.

When properly formatted, it looks like this:

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

The >>> and error message tells me that you typed python fibo.py 50 at the Python prompt.

It should be typed in a Command Prompt window or at a PowerShell prompt.

1 Like

Thank you both. I went back to the document and can see that the prompt where the command was executed is $, not >>>. Works like a charm.

1 Like