Wiring not done correctly with PyInstaller
See original GitHub issueHi, first off, I’d like to say thank you for this amazing library. So easy to use and so efficient.
Now, the problem I have is that my project runs perfectly when I simply run the python script, but when I bundle it into an exe with PyInstaller, it raises this error :
TypeError: 'Provide' object is not subscriptable
I have tested the following :
class Main:
def __init__(self):
self.container = Container()
with open(CONFIG_FILE_PATH) as jsonfile:
self.container.config.from_dict(json.load(jsonfile))
self.container.wire(packages=[photovisual, gui])
print('config : ' + str(self.container.config()))
@inject
def start(self, config: dict = Provide[Container.config]):
print("config : "+str(config))
root = Tk()
configwin = ConfigDialog(root)
ses = SessionWindow(root)
configwin.onGo(ses.setupWindow)
configwin.pack()
root.mainloop()
The first print works fine, it prints out the config dictionnary. The second one in method start when I use @inject doesn’t. It prints the following :
config : <dependency_injector.wiring.Provide object at 0x0000013EFB974070>
It looks a lot like [Issue #328] (https://github.com/ets-labs/python-dependency-injector/issues/328), though I must say it again, my script does actually work, the error only appears when I try to run the executable file created by PyInstaller. All my packages have __init__.py
and I’m not making any declaration during declaative phase.
So my guess is that somehow, bundling the project with PyInstaller breaks the wiring. Has someone ever use this library with PyInstaller ?
Prior to this error, I also had a ModuleNotFoundError
when building the executable. The module dependency_injector.errors
could not be found, so I added it in the hidden imports. These two issues may or may not be related…
Here is my Container class :
class Container(containers.DeclarativeContainer):
config = providers.Configuration()
drive_service = providers.Singleton(drive.DriveUploader, credentials=config.creds)
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:15 (7 by maintainers)
Top GitHub Comments
This issue still happens to me.
I’m already using the modules wiring, as described in the Dependecy-Injector example (https://pypi.org/project/dependency-injector/):
The error appears when running the EXE file from Windows after packaging it with PyInstaller (with the options -D -w). Running the application directly from Python doesn’t show the problem
ModuleNotFoundError: No module named 'dependency_injector.errors'
Hi @veotani. Got it, good that everything works on your end. I’m also going to take a look if I could fix “startswith first arg” issue from 4.4 to support more versions.