PyInstaller Hidden Imports

11,355

You can either:

  • update the spec file manually to include urllib3

or

  • run pyinstaller with the argument --hidden-import=urllib3
Share:
11,355
Andrew B
Author by

Andrew B

Updated on June 24, 2022

Comments

  • Andrew B
    Andrew B about 2 years

    I have a fully working Python program that uses the following imports:

    import json
    import requests
    from natsort import natsorted
    

    However, when I try to compile it to an executable using PyInstaller, I get the following errors:

    Note: May not be perfect, as it was captured by my reaction times and a screenshot:

    File "site-packages\requests\packages\urllib3\packages\six.py", line 82, in _import_module
    ImportError: No module named 'queue'
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
    File "huepy3.py", line 2, in <module>
    File "c:\users\andrew\appdata\local\programs\python\python35-32\lib\site-packages\PyInstaller\loader\pyimodo3_importer
    py", line 389, in load_module
    exec(bytecode, module.__dict__)
    File "site-packages\requests\__init__.py", line 63, in <module>
    File "c:\users\andrew\appdata\local\programs\python\python35-32\lib\site-packages\PyInstaller\loader\pyimodo3_importer
    py", line 389, in load_module
    exec(bytecode, module.__dict__)
    File "site-packages\requests\utils.py", line 24, in <module>
    File "c:\users\andrew\appdata\local\programs\python\python35-32\lib\site-packages\PyInstaller\loader\pyimodo3_importer
    py", line 389, in load_module
    exec(bytecode, module.__dict__)
    File "site-packages\requests\_internal_utils.py", line 11, in <module>
    File "c:\users\andrew\appdata\local\programs\python\python35-32\lib\site-packages\PyInstaller\loader\pyimodo3_importer
    py", line 389, in load_module
    exec(bytecode, module.__dict__)
    File "site-packages\requests\compat.py", line 11, in <module>
    File "c:\users\andrew\appdata\local\programs\python\python35-32\lib\site-packages\PyInstaller\loader\pyimodo3_importer
    py", line 389, in load_module
    exec(bytecode, module.__dict__)
    File "site-packages\requests\packages\__init__.py", line 29, in <module>
    ImportError: No module named 'urllib3'
    Failed to execute script huepy3
    

    I read the error, and tried to import urllib3 in my code as well. That returned the same errors as well. I'm thinking it's down to the location of urllib3 in relation to requests, but how can I solve this? I read online about FileDialog, and again it returned the same error.

    Any pointers on this would be much appreciated.

    Edit: It's not just the queue import problem, it's more of how to change the paths the library requests is trying to import from and how pyinstaller is going to get those paths in the first instance.

    Edit 2: Ok, maybe I should ask how PyInstaller compiles the dependencies it finds and where it stores them? I could then give it a shot myself.

    Edit 3: Through hours of crawling the web I believe I might be after hidden imports. How do those works for getting urllib3 in?