I wrote a package, which lives in /home/michael/python/mcdb-mail-parser/
The file structure in there is:
.
├── __init__.py
├── mcdb_mail_parser
│ ├── __init__.py
│ ├── MCDBAttachment.py
│ ├── MCDBEmail.py
│ ├── Options.py
├── mcdb-mail-parser.conf.sample
├── mcdb-mail-parser.py
├── README.md
mcdb-mail-parser.py
imports from the mcdb_mail_parser
subdirectory.
if I run the scripts from the source directory (/home/michael/python/src/mcdb_mail_parser
) it works fine because the mcdb_mail_parser
directory is immediately available in the current directory. However, I need to run it from the home directory of another user (via a cronjob, or from another script via subprocess), python complains it cannot find the module:
I tried to execute it with python3 -m /home/michael/python/src/mcdb_mail_parser
, but it complains:
michael@d8:~$ python3 -m /home/michael/python/mcdb-mail-parser/
/usr/bin/python3: No module named /home/michael/python/mcdb-mail-parser/
I am not sure where to go from here. I think that it's a path issue. I could add /home/michael/python/src/mcdb_mail_parser
to the system path, or perhaps python path, but that seems like the wrong solution. I certainly don't want to hard code paths into any scripts either.
How do I tell python: "Run the mcdb-mail-parser.py
script from /home/michael/python/src/mcdb_mail_parser
directory?
Closing notes
The accepted answer was useful, and so was the link they provided. Here's what I eventually did:
1. I moved the contents of mcdb_mail_parser
from the subdirectory into the same directory as README.md
, thus removing one level of complexity.
2. I added the import statements to __init__.py
as suggested.
3. Python complained it couldn't find __main__.py
, so I renamed mcdb-mail-parser.py
to __main__.py