0

I am trying to run a stand-alone python file partitions.py that is in my home folder. When I type the command "python3 partition.py" the script runs.

However, when I type "python3 -m partition.py" it gives me an error "/usr/local/bin/python3: No module named partition.py"

I do not know why this is the case. Any help would be greatly appreciated. Thanks

Floki
  • 21
  • 1
  • Is the file `partition.py` located in a directory that is in your `PYTHONPATH` environment variable? – senshin Jan 21 '14 at 21:33
  • Because there isn't a *module* named `partition.py`; there is a *file* named `partition.py`. The corresponding *module* is named `partition`, which is what the `-m flag expects. Please see the linked duplicate for a full overview of `-m`. – Karl Knechtel Jul 19 '23 at 02:58

2 Answers2

4

To run the module as script directly use:

python3 -m partition

(without the .py ending).

That will cause python to search sys.path for a module called partition and execute it. partition.py in this context would mean a module in a file partition/py.py.

mata
  • 67,110
  • 10
  • 163
  • 162
0

See the doc, specifically that the module must be on the path, and the extension shouldn't be included.

CDspace
  • 2,639
  • 18
  • 30
  • 36