Requires users to configure hidden imports when used in a PyInstaller project.
See original GitHub issueappdirs
does not suffer from this issue because all the source code is in one file appdirs.py
For example with app.py
:
from platformdirs import user_data_dir
print(user_data_dir("appname"))
building this and running it gives an error due to the conditional imports PyInstaller can’t detect.
> pyinstaller app.py
> .\dist\app\app.exe
Traceback (most recent call last):
File "app.py", line 1, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
File "platformdirs\__init__.py", line 31, in <module>
File "platformdirs\__init__.py", line 27, in _set_platform_dir_class
File "importlib\__init__.py", line 127, in import_module
ModuleNotFoundError: No module named 'platformdirs.windows'
[1348] Failed to execute script 'app' due to unhandled exception!
Users can fix this themselves by configuring a hidden import.
> pyinstaller app.py --hidden-import platformdirs.windows
> .\dist\app\app.exe
C:\Users\<User>\AppData\Local\appname\appname
However it would be nice if platformdirs
provided a hook specifying the hidden imports.
PyInstaller provides a mechanism for doing this https://pyinstaller.readthedocs.io/en/stable/hooks.html#provide-hooks-with-package
Especially since I imagine the hidden import would be different depending on the platform.
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
How to set up hidden imports in pyinstaller - Stack Overflow
The hiddenimports are used to specify imports that can't be detected by pyinstaller, not the paths to those imports.
Read more >When Things Go Wrong — PyInstaller 5.7.0 documentation
If Analysis thinks it has found all the imports, but the app fails with an import error, the problem is a hidden import;...
Read more >Pyinstaller: Module not found when running .exe when ...
I have tried explicitly importing openpyxl and that didn't work and I have also used --hidden-import : call venv\Scripts\activate pyinstaller --onefile ...
Read more >Using PyInstaller to Easily Distribute Python Applications
You can also use --hidden-import multiple times in the same command. This option requires the name of the package that you want to...
Read more >PyInstaller Documentation - Read the Docs
You can write “hook” files that inform PyInstaller of hidden imports. If you create a “hook” for a package that other users might...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I went ahead and put up https://github.com/pyinstaller/pyinstaller-hooks-contrib/pull/312 just in case.
I think it is a good suggestion, so it must be done. I wrote some TODO for discussion:
setup.cfg
hiddenimports
, each platform has its own import Note: Pyinstaller does not support AndroidI suppose i can get started after adding
user_documents_dir