Reputation: 3773
I cannot seem to get pyinstaller to correctly package a module.
Example module structure
myapp/
__main__.py
mysubmodule.py
Example __main__.py
content
"""My __main__.py."""
import myapp.mysubmodule
print("Done")
If I run python -m myapp
it runs with no errors and prints Done
.
If I run pyinstaller myapp
I get errors stating it's a directory.
If I run pyinstaller myapp/__main__.py
it builds but when I execute the dist/__main__/__main__
which is generated I get ModuleNotFoundError: No module named 'myapp'
.
How can I get pyinstaller to include myapp
as a module so it can be imported?
Upvotes: 2
Views: 6262
Reputation: 5783
Add an __init__.py
otherwise myapp
it is not a valid module/package.
The missing file is:
myapp/__init__.py
EDIT:
You can leave __init__.py
empty.
Read the documentation here.
The
__init__.py
files are required to make Python treat the directories as containing packages; this is done to prevent directories with a common name, such as string, from unintentionally hiding valid modules that occur later on the module search path. In the simplest case,__init__.py
can just be an empty file, but it can also execute initialization code for the package or set the__all__
variable, described later.
Upvotes: 1