Skip to content

Wiring not done correctly with PyInstaller #438

Open
@saledemon

Description

@saledemon

Hi, 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] (#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)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions