简体   繁体   English

PyInstaller隐藏的进口

[英]PyInstaller Hidden Imports

I have a fully working Python program that uses the following imports: 我有一个完全工作的Python程序,它使用以下导入:

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: 但是,当我尝试使用PyInstaller将其编译为可执行文件时,我收到以下错误:

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. 我读了错误,并尝试在我的代码中导入urllib3。 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? 我认为这取决于urllib3与请求的关系,但我该如何解决这个问题呢? I read online about FileDialog, and again it returned the same error. 我在线阅读有关FileDialog的信息,并再次返回相同的错误。

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. 编辑:这不仅仅是队列导入问题,更多的是如何更改库请求尝试导入的路径以及pyinstaller如何在第一个实例中获取这些路径。

Edit 2: Ok, maybe I should ask how PyInstaller compiles the dependencies it finds and where it stores them? 编辑2:好的,也许我应该问PyInstaller如何编译它找到的依赖项以及它存储在哪里? I could then give it a shot myself. 我可以自己试一试。

Edit 3: Through hours of crawling the web I believe I might be after hidden imports. 编辑3:通过网络爬行数小时,我相信我可能会隐藏进口。 How do those works for getting urllib3 in? 这些如何用于获取urllib3?

You can either: 你可以:

  • update the spec file manually to include urllib3 手动更新spec文件以包含urllib3

or 要么

  • run pyinstaller with the argument --hidden-import=urllib3 使用参数--hidden-import=urllib3运行--hidden-import=urllib3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM