pyinstaller / pyinstaller/pyinstaller
Handle relative imports in a package's __main__.py
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 13.1k
- Forks
- 2k
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 11
Description
I have a runnable package with __main__.py:
foo/
__init__.py
__main__.py
I can execute this package by running python -m foo. However you cannot directly create a PyInstaller application from this package:
- If you try
pyinstaller -F foo, you'll getIOError: [Errno 21] Is a directory. - If you try
pyinstaller -F foo/__main__.pyit will build, but then you'll getValueError: Attempted relative import in non-packagewhen you try to run it, presumably because it took__main__.pyout of the context of its package.
The work around is to create a small "stub" application that lives outside of the package and calls into it:
from foo import main
main()
...and then point PyInstaller at the stub.
It seems that PyInstaller should be able to create an application by being pointed at the package directory.
I'm sorry if this has already been addressed, but I've been unable to find anything in the documentation or anywhere else:
- How can I convert a package to an exe using pyinstaller? (StackOverflow)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the three cases in the issue: python -m foo, pyinstaller -F foo, and pyinstaller -F foo/__main__.py, using the shown package layout. Then trace PyInstaller's package entry-point handling. Done means a package directory can produce a runnable application while preserving relative imports, without requiring an external stub.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- build-system
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100