Working Around "modulenotfounderror: ...'__main__' Is Not A Package" Error
I've got a project running on a server with the structure proj __init__.py module_a.py module_b.py main.py And in the header of main.py, I import from other module
Solution 1:
Keep your imports relative, without using the package full path, so that you have the flexibility of renaming it as you wish, like in
from .module_aimport func1
Then in your local environment, change your current dir to the proj
parent folder and run:
python -m proj.main
An alternative would be to rename main.py
to __main__.py
and then just writing
python -m proj
will do. But that may affect the behaviour on the server if you copy the files as is.
Packages are usually to be imported. This is a common problem when we start running from arbitrary scripts located inside the package (in this case main.py
). If the package is simply imported from outside, everything works.
Post a Comment for "Working Around "modulenotfounderror: ...'__main__' Is Not A Package" Error"