question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Wiring not done correctly with PyInstaller

See original GitHub issue

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] (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:open
  • Created 2 years ago
  • Reactions:1
  • Comments:15 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
serlesencommented, Feb 2, 2022

This issue still happens to me.

  • Python 3.8.5
  • Depencency-Injector 4.38.0
  • PyInstaller 4.8 (also tried with 4.5.1)

I’m already using the modules wiring, as described in the Dependecy-Injector example (https://pypi.org/project/dependency-injector/):

from dependency_injector.wiring import Provide, inject


@inject
def main(
    service = Provide[Container.service],
):
    service.start()


if __name__ == "__main__":
    container = Container()
    container.wire(modules=[__name__])
    main()

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'

1reaction
rmk135commented, Sep 1, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Problems with Pyinstaller & and Common Fixes - YouTube
uite error prone, and many people have run into alot of constant errors and problems while using Pyinstaller. This Video was created for...
Read more >
Why does Pyinstaller not compile Tkinter properly? [duplicate]
My batchmates and I are working on an arcade game project for which we used Tkinter for the main GUI and os module...
Read more >
Using Spec Files - PyInstaller
PyInstaller analyzes myscript.py and: Writes myscript.spec in the same folder as the script. Creates a folder build in the same folder as the...
Read more >
Using PyInstaller to Easily Distribute Python Applications
In this step-by-step tutorial, you'll learn how to use PyInstaller to turn your Python application into an executable with no dependencies or installation...
Read more >
Qt for Python & PyInstaller - Qt Documentation
As of March 2021, Qt 6 is not supported yet. PyInstaller is unable to properly deploy Qt; the Qt plugins are not copied....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found