PyInstaller and PyQt5 error: ImportError: DLL load failed while importing QtWidgets: The specified procedure could not be found

huangapple go评论68阅读模式
英文:

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(
    [&#39;main.py&#39;],
    pathex=[
        &#39;C:\\Users\\user\\anaconda3\\Lib&#39;, &#39;C:\\Users\\user\\anaconda3\\Lib\\site-packages&#39;, &#39;C:\\Users\\user\\anaconda3\\libs&#39;, 
        &#39;C:\\Users\\user\\anaconda3\\Lib\\site-packages\\PyQt5&#39;, &#39;C:\\Users\\user\\anaconda3\\Lib\\site-packages\\PyQt5\\Qt5\\bin&#39;,
        &#39;C:\\Users\\user\\Desktop\\am_gui&#39;],
    binaries=[],
    datas=[],
    hiddenimports=[&#39;PyQt5&#39;, &#39;PyQt5.QtCore&#39;, &#39;PyQt5.QtWidgets&#39;, &#39;PyQt6&#39;, &#39;PyQt6.QtCore&#39;, &#39;PyQt6.QtWidgets&#39;, &#39;matplotlib&#39;, &#39;numpy&#39;, &#39;pandas&#39;, &#39;sqlalchemy&#39;, &#39;datetime&#39;],
    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=&#39;main&#39;,
    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=&#39;main&#39;,
)

While running .exe file I get:

Traceback (most recent call last):
  File &quot;main.py&quot;, line 1, in &lt;module&gt;
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.

huangapple
  • 本文由 发表于 2023年4月17日 19:05:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/76034482.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定