Search code examples
pythonpyinstallerhidden

Pyinstaller --hidden-imports not wirking


I'm trying to build an exe file from a python game using PyBox2D and Pyglet.

When I build the exe there occurs an error that a module cannot be imported:
Unable to import the back-end pyglet: module 'gui.backends' has no attribute 'pyglet_framework'
I guess this happens because this file only gets imported indirectly/hidden from another file with __import__()

This is my project hierarchy:
enter image description here

I've tried to add the file to pyinstaller on multiple ways. From the directory /SpaceJam/building I've tried calling:

pyinstaller.exe --onefile "../game/spacejam.py" --hidden-import="gui/framework/backends/pyglet_framework.py"
pyinstaller.exe --onefile "../game/spacejam.py" --hidden-import="../gui/framework/backends/pyglet_framework.py"
pyinstaller.exe --onefile "../game/spacejam.py" --hidden-import="../gui/framework/backends/pyglet_framework"
pyinstaller.exe --onefile "../game/spacejam.py" --hidden-import="../gui/framework/backends/*"

but none of that seemed to change anything in the error message.

I feel like I'm missing something obvious. Does somebody have an idea what I might be doing wrong or why the --hidden-import argument doesn't seem to work?


Solution

  • That argument expects a module name, not a filesystem path. How would you import it?

    I'm not totally clear on how your project is set up, but try

    --hidden-import gui.backends.pyglet_framework