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

2
  • Is the file partition.py located in a directory that is in your PYTHONPATH environment variable? Commented Jan 21, 2014 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`. Commented Jul 19, 2023 at 2:58

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

In your case the home directory presented in sys.path.
0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.