英文:
PyInstaller and PyQt5 error: ImportError: DLL load failed while importing QtWidgets: The specified procedure could not be found
问题
I encounter an error while trying to run a PyQt5 app made with PyInstaller. There are almost no warnings during building, yet I have a lot of "missing module" warnings in "warn.txt".
This is how my imports in python code look like:
from PyQt5 import QtWidgets, QtCore
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg
from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT
import matplotlib.pyplot as plt
import numpy as np
and this is how my .spec file looks like:
# -*- mode: python ; coding: utf-8 -*-
block_cipher = None
a = Analysis(
    ['main.py'],
    pathex=[
        'C:\\Users\\user\\anaconda3\\Lib', 'C:\\Users\\user\\anaconda3\\Lib\\site-packages', 'C:\\Users\\user\\anaconda3\\libs', 
        'C:\\Users\\user\\anaconda3\\Lib\\site-packages\\PyQt5', 'C:\\Users\\user\\anaconda3\\Lib\\site-packages\\PyQt5\\Qt5\\bin',
        'C:\\Users\\user\\Desktop\\am_gui'],
    binaries=[],
    datas=[],
    hiddenimports=['PyQt5', 'PyQt5.QtCore', 'PyQt5.QtWidgets', 'PyQt6', 'PyQt6.QtCore', 'PyQt6.QtWidgets', 'matplotlib', 'numpy', 'pandas', 'sqlalchemy', 'datetime'],
    hookspath=[],
    hooksconfig={},
    runtime_hooks=[],
    excludes=[],
    win_no_prefer_redirects=False,
    win_private_assemblies=False,
    cipher=block_cipher,
    noarchive=False,
)
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)
exe = EXE(
    pyz,
    a.scripts,
    [],
    exclude_binaries=True,
    name='main',
    debug=True,
    bootloader_ignore_signals=False,
    strip=False,
    upx=False,
    console=True,
    disable_windowed_traceback=False,
    argv_emulation=False,
    target_arch=None,
    codesign_identity=None,
    entitlements_file=None,
)
coll = COLLECT(
    exe,
    a.binaries,
    a.zipfiles,
    a.datas,
    strip=False,
    upx=False,
    upx_exclude=[],
    name='main',
)
While running .exe file I get:
Traceback (most recent call last):
  File "main.py", line 1, in <module>
ImportError: DLL load failed while importing QtWidgets: The specified procedure could not be found.
英文:
I encounter an error while trying to run a PyQt5 app made with PyInstaller. There are almost no warnings during building, yet I have a lot of "missing module" warnings in "warn.txt".
This is how my imports in python code look like:
from PyQt5 import QtWidgets, QtCore
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg
from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT
import matplotlib.pyplot as plt
import numpy as np
and this is how my .spec file looks like:
# -*- mode: python ; coding: utf-8 -*-
block_cipher = None
a = Analysis(
    ['main.py'],
    pathex=[
        'C:\\Users\\user\\anaconda3\\Lib', 'C:\\Users\\user\\anaconda3\\Lib\\site-packages', 'C:\\Users\\user\\anaconda3\\libs', 
        'C:\\Users\\user\\anaconda3\\Lib\\site-packages\\PyQt5', 'C:\\Users\\user\\anaconda3\\Lib\\site-packages\\PyQt5\\Qt5\\bin',
        'C:\\Users\\user\\Desktop\\am_gui'],
    binaries=[],
    datas=[],
    hiddenimports=['PyQt5', 'PyQt5.QtCore', 'PyQt5.QtWidgets', 'PyQt6', 'PyQt6.QtCore', 'PyQt6.QtWidgets', 'matplotlib', 'numpy', 'pandas', 'sqlalchemy', 'datetime'],
    hookspath=[],
    hooksconfig={},
    runtime_hooks=[],
    excludes=[],
    win_no_prefer_redirects=False,
    win_private_assemblies=False,
    cipher=block_cipher,
    noarchive=False,
)
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)
exe = EXE(
    pyz,
    a.scripts,
    [],
    exclude_binaries=True,
    name='main',
    debug=True,
    bootloader_ignore_signals=False,
    strip=False,
    upx=False,
    console=True,
    disable_windowed_traceback=False,
    argv_emulation=False,
    target_arch=None,
    codesign_identity=None,
    entitlements_file=None,
)
coll = COLLECT(
    exe,
    a.binaries,
    a.zipfiles,
    a.datas,
    strip=False,
    upx=False,
    upx_exclude=[],
    name='main',
)
While running .exe file I get:
Traceback (most recent call last):
  File "main.py", line 1, in <module>
ImportError: DLL load failed while importing QtWidgets: The specified procedure could not be found.
答案1
得分: 0
这与Pyqt5和Pyinstaller兼容性的版本有关。Pyqt5的版本是多少,请尝试使用小于5.15.3的版本。
英文:
This has to do with the Version of Pyqt5 and Pyinstaller compatibility. What is the Pyqt5 version, try using less than 5.15.3
答案2
得分: 0
我正在使用Python 3.11.3,PyQt5 5.15.9和PyInstaller 5.10.1。
出于某种原因,在导入PyQt5之前,在代码中明确导入pandas可以解决这个问题。
英文:
I am using Python 3.11.3, PyQt5 5.15.9 and PyInstaller 5.10.1.
For whatever reason importing pandas explicit in code before importing PyQt5 solves this problem for me.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论