【问题标题】:"ImportError: DLL load failed while importing" while using PyInstaller使用 PyInstaller 时出现“ImportError: DLL load failed while importing”
【发布时间】:2021-02-16 12:22:19
【问题描述】:

我正在尝试使用 PyInstaller 打包 PyQt5 Python 应用程序。

当我正常打包时,不使用UPX,它工作正常。但是,当我开始使用 UPX 时,我开始遇到很多问题。我必须使用--upx-exclude "vcruntime140.dll" 来防止该文件被损坏。

然后,我遇到了这个问题。

Traceback (most recent call last):
  File "main.py", line 3, in <module>
ImportError: DLL load failed while importing QtWidgets: The parameter is incorrect.
[26400] Failed to execute script main

这是main.py的开头:

import sys
import PyQt5
from PyQt5 import QtWidgets
from PyQt5.QtGui import QIcon

我读到here(我认为类似的问题)我可能在隐藏导入方面遇到问题,所以我使用--hidden-import "PyQt5" 运行PyInstaller 命令,然后使用--hidden-import "PyQt5" --hidden-import "QtWidgets"。但我一直收到同样的错误,DLL load failed while importing QTWidgets

我使用的完整 PyInstaller 命令是:

pyinstaller -n "[exe name]" -i "[icon file path].ico" --upx-dir "[path to UPX]\upx-3.96-win64" --upx-exclude "vcruntime140.dll" --hidden-import "PyQt5" --hidden-import "QtWidgets" --clean main.py

我可以做些什么来修复这个错误?

【问题讨论】:

    标签: python pyqt pyqt5 pyinstaller


    【解决方案1】:

    本周早些时候我遇到了完全相同的问题。 我通过完全禁用 UPX 来修复它。如果您仍想压缩其中一些,您可以通过将越来越多的 QT DLL 添加到 UPX 排除列表来确定哪些具体它正在损坏,但现在我可以完全禁用它。

    我尝试了很多东西——不同版本的 PyQT5,不同版本的其他库,都没有任何效果。

    如果您有基于文件夹构建的 .spec 文件,请务必在 exe 和 coll 部分禁用 UPX。

    【讨论】:

    • 是的,禁用它可以修复它。不过很遗憾,因为我真的可以使用这种压缩方式!
    猜你喜欢
    • 2021-05-17
    • 1970-01-01
    • 1970-01-01
    • 2020-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-28
    • 1970-01-01
    相关资源
    最近更新 更多