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 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.