如何修复“导入QtWidgets时DLL加载失败”?

时间:2020-11-04 08:17:23

标签: python qt pyqt5 py2exe python-3.8

问题:

因此,编译后,在dist文件夹中有“ PyQt5.Qt.pyd”文件, 但我收到此错误:

from rq import Queue
from redis import Redis
from rq_scheduler import Scheduler

queue = Queue(connection=Redis())
scheduler = Scheduler(queue=queue)

我非常确定,来自“ C:\ Program Files(x86)\ Python38-32 \ Lib \ site-packages \ PyQt5 \ Qt的” Qt“ 文件夹< / strong>,我猜它在编译后会转换为“ PyQt5.Qt.pyd” 文件,是造成此错误的原因。因为当我将此位置添加到Windows路径:“ C:\ Program Files(x86)\ Python38-32 \ Lib \ site-packages \ PyQt5 \ Qt \ bin” 时,编译后的程序可以正常工作


我的临时解决方法是:

我将“ Qt”文件夹复制到“ dist”,并制作了一个批处理脚本,将“。\ dist \ Qt \ bin”添加到当前CMD窗口的PATH中。我的客户现在要对其进行测试...但这还远远不是最终解决方案...该怎么办?

(我还尝试将“ Qt”中的“ bin”或“ platform \ qwindows.dll”复制到dist,但是没有运气...)

我将对此有任何帮助或建议。预先感谢!


我的信息:

操作系统信息: Windows 10 x64,Python 3.8.6 x32

点冻结:

Traceback (most recent call last):
  File "main.py", line 102, in <module>
  File "<frozen zipimport>", line 259, in load_module
  File "<loader>", line 10, in <module>
  File "<loader>", line 8, in __load
ImportError: (DLL load failed while importing QtWidgets: The specified module could not be found.) 'Z:\\Project\\dist\\PyQt5.QtWidgets.pyd'

py2exe setup.py:

altgraph==0.17
cachetools==4.1.1
fbs==0.9.0
future==0.18.2
macholib==1.14
pefile==2019.4.18
Pillow==8.0.1
 py2exe==0.10.0.2
PyInstaller==3.4
 PyQt5==5.15.1
PyQt5-sip==12.8.1
pywin32==228
pywin32-ctypes==0.2.0
six==1.15.0

1 个答案:

答案 0 :(得分:1)

将所有 dll 从 PyQt5\Qt\bin 复制到 dist,除了以 Qt5* 开头的那些(如果您不使用 direct3d 或 opengl,您可能不需要 d3dcompiler_47、libEGL、libGLESv2 和 opengl32sw)

我建议您尝试在新安装的 Windows(可能在虚拟机中)上运行使用 py2exe 转换的应用程序,以查看它是否有其他依赖项。

更新:实际上,我只需要为 Visual Studio 2015、2017 和 2019 安装 Microsoft Visual C++ Redistributable,无需复制任何 dll 文件。 https://support.microsoft.com/en-us/topic/the-latest-supported-visual-c-downloads-2647da03-1eea-4433-9aff-95f26a218cc0