无法运行pyinstaller捆绑的基于QT的GUI应用程序,控制台输出显示它是由于导入错误引起的:
ImportError: unable to find Qt5Core.dll on PATH
最初,pyqt5 / pyqt和pyinstaller来自公寓。我试图从pypi重新安装pyqt5和pyinstaller,但不能解决问题。
我检查了pyinstaller dist目录,它包含所有需要的dll。当我在conda env中时(启动conda控制台,然后在控制台中运行捆绑的应用程序),捆绑的应用程序将正常运行。我检查了加载的dll,它们都在dist目录或系统默认目录中。
我在windows 10 x64 [Ver 10.0.18362.175]
上,Python版本是miniconda的3.7.3
。
conda软件包:
# packages in environment at D:\Miniconda3:
#
# Name Version Build
altgraph 0.16.1 pypi_0
asn1crypto 0.24.0 py37_0
attrs 19.1.0 py37_1
backcall 0.1.0 py37_0
blas 1.0 mkl
bleach 3.1.0 py37_0
bzip2 1.0.7 he774522_0
ca-certificates 2019.5.15 0
certifi 2019.6.16 py37_0
cffi 1.12.3 py37h7a1dbc1_0
chardet 3.0.4 py37_1
colorama 0.4.1 py37_0
conda 4.7.5 py37_0
conda-package-handling 1.3.10 py37_0
cryptography 2.7 py37h7a1dbc1_0
decorator 4.4.0 py37_1
defusedxml 0.6.0 py_0
entrypoints 0.3 py37_0
future 0.17.1 pypi_0
icc_rt 2019.0.0 h0cc432a_1
icu 58.2 ha66f8fd_1
idna 2.8 py37_0
intel-openmp 2019.4 245
ipykernel 5.1.1 py37h39e3cac_0
ipython 7.6.0 py37h39e3cac_0
ipython_genutils 0.2.0 py37_0
ipywidgets 7.4.2 py37_0
jedi 0.13.3 py37_0
jinja2 2.10.1 py37_0
jpeg 9b hb83a4c4_2
jsonschema 3.0.1 py37_0
jupyter 1.0.0 py37_7
jupyter_client 5.2.4 py37_0
jupyter_console 6.0.0 py37_0
jupyter_core 4.5.0 py_0
jupyterlab 0.35.4 py37hf63ae98_0
jupyterlab_server 0.2.0 py37_0
libarchive 3.3.3 h0643e63_5
libiconv 1.15 h1df5818_7
libpng 1.6.37 h2a8f88b_0
libsodium 1.0.16 h9d3ae62_0
libxml2 2.9.9 h464c3ec_0
lz4-c 1.8.1.2 h2fa13f4_0
lzo 2.10 h6df0209_2
m2w64-gcc-libgfortran 5.3.0 6
m2w64-gcc-libs 5.3.0 7
m2w64-gcc-libs-core 5.3.0 7
m2w64-gmp 6.1.0 2
m2w64-libwinpthread-git 5.0.0.4634.697f757
macholib 1.11 pypi_0
markupsafe 1.1.1 py37he774522_0
menuinst 1.4.16 py37he774522_0
mistune 0.8.4 py37he774522_0
mkl 2019.4 245
mkl_fft 1.0.12 py37h14836fe_0
mkl_random 1.0.2 py37h343c172_0
msys2-conda-epoch 20160418 1
nbconvert 5.5.0 py_0
nbformat 4.4.0 py37_0
notebook 5.7.8 py37_0
numpy 1.16.4 py37h19fb1c0_0
numpy-base 1.16.4 py37hc3f5095_0
openssl 1.1.1c he774522_1
pandoc 2.2.3.2 0
pandocfilters 1.4.2 py37_1
parso 0.5.0 py_0
pefile 2019.4.18 pypi_0
pickleshare 0.7.5 py37_0
pip 19.1.1 py37_0
prometheus_client 0.7.1 py_0
prompt_toolkit 2.0.9 py37_0
pycosat 0.6.3 py37hfa6e2cd_0
pycparser 2.19 py37_0
pycrypto 2.6.1 pypi_0
pygments 2.4.2 py_0
pyinstaller 3.4 pypi_0
pyopenssl 19.0.0 py37_0
pyqt 5.9.2 py37h6538335_2
pyqt5 5.13.0 pypi_0
pyqt5-sip 4.19.18 pypi_0
pyrsistent 0.14.11 py37he774522_0
pysocks 1.7.0 py37_0
python 3.7.3 h8c8aaf0_0
python-dateutil 2.8.0 py37_0
python-libarchive-c 2.8 py37_9
pywin32 223 py37hfa6e2cd_1
pywin32-ctypes 0.2.0 pypi_0
pywinpty 0.5.5 py37_1000
pyzmq 18.0.0 py37ha925a31_0
qt 5.9.7 vc14h73c81de_0
qtconsole 4.5.1 py_0
requests 2.22.0 py37_0
ruamel_yaml 0.15.46 py37hfa6e2cd_0
scipy 1.2.1 py37h29ff71c_0
send2trash 1.5.0 py37_0
setuptools 41.0.1 py37_0
sip 4.19.8 py37h6538335_0
six 1.12.0 py37_0
sqlite 3.28.0 he774522_0
terminado 0.8.2 py37_0
testpath 0.4.2 py37_0
tornado 6.0.3 py37he774522_0
tqdm 4.32.1 py_0
traitlets 4.3.2 py37_0
urllib3 1.24.2 py37_0
vc 14.1 h0510ff6_4
vs2015_runtime 14.15.26706 h3a45250_4
wcwidth 0.1.7 py37_0
webencodings 0.5.1 py37_1
wheel 0.33.4 py37_0
widgetsnbextension 3.4.2 py37_0
win_inet_pton 1.1.0 py37_0
wincertstore 0.2 py37_0
winpty 0.4.3 4
xz 5.2.4 h2fa13f4_4
yaml 0.1.7 hc54c509_2
zeromq 4.3.1 h33f27b4_3
zlib 1.2.11 h62dcd97_3
zstd 1.3.7 h508b16e_0
pyinstaller dist目录文件:
PS C:\Users\xxx\Idp\dist\main> dir
Directory: C:\Users\xxx\Idp\dist\main
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 2019/7/9 15:04 Crypto
d----- 2019/7/9 15:04 PyQt5
-a---- 2019/7/8 16:35 19208 api-ms-win-core-console-l1-1-0.dll
-a---- 2019/7/8 16:35 18696 api-ms-win-core-datetime-l1-1-0.dll
-a---- 2019/7/8 16:35 18696 api-ms-win-core-debug-l1-1-0.dll
-a---- 2019/7/8 16:35 18696 api-ms-win-core-errorhandling-l1-1-0.dll
-a---- 2019/7/8 16:35 22280 api-ms-win-core-file-l1-1-0.dll
-a---- 2019/7/8 16:35 18696 api-ms-win-core-file-l1-2-0.dll
-a---- 2019/7/8 16:35 18696 api-ms-win-core-file-l2-1-0.dll
-a---- 2019/7/8 16:35 18696 api-ms-win-core-handle-l1-1-0.dll
-a---- 2019/7/8 16:35 19208 api-ms-win-core-heap-l1-1-0.dll
-a---- 2019/7/8 16:35 18696 api-ms-win-core-interlocked-l1-1-0.dll
-a---- 2019/7/8 16:35 19720 api-ms-win-core-libraryloader-l1-1-0.dll
-a---- 2019/7/8 16:35 21256 api-ms-win-core-localization-l1-2-0.dll
-a---- 2019/7/8 16:35 19208 api-ms-win-core-memory-l1-1-0.dll
-a---- 2019/7/8 16:35 18696 api-ms-win-core-namedpipe-l1-1-0.dll
-a---- 2019/7/8 16:35 19720 api-ms-win-core-processenvironment-l1-1-0.dll
-a---- 2019/7/8 16:35 20744 api-ms-win-core-processthreads-l1-1-0.dll
-a---- 2019/7/8 16:35 19208 api-ms-win-core-processthreads-l1-1-1.dll
-a---- 2019/7/8 16:35 18184 api-ms-win-core-profile-l1-1-0.dll
-a---- 2019/7/8 16:35 19208 api-ms-win-core-rtlsupport-l1-1-0.dll
-a---- 2019/7/8 16:35 18696 api-ms-win-core-string-l1-1-0.dll
-a---- 2019/7/8 16:35 20744 api-ms-win-core-synch-l1-1-0.dll
-a---- 2019/7/8 16:35 19208 api-ms-win-core-synch-l1-2-0.dll
-a---- 2019/7/8 16:35 19720 api-ms-win-core-sysinfo-l1-1-0.dll
-a---- 2019/7/8 16:35 19208 api-ms-win-core-timezone-l1-1-0.dll
-a---- 2019/7/8 16:35 18696 api-ms-win-core-util-l1-1-0.dll
-a---- 2019/7/8 16:35 19720 api-ms-win-crt-conio-l1-1-0.dll
-a---- 2019/7/8 16:35 22792 api-ms-win-crt-convert-l1-1-0.dll
-a---- 2019/7/8 16:35 19208 api-ms-win-crt-environment-l1-1-0.dll
-a---- 2019/7/8 16:35 20744 api-ms-win-crt-filesystem-l1-1-0.dll
-a---- 2019/7/8 16:35 19720 api-ms-win-crt-heap-l1-1-0.dll
-a---- 2019/7/8 16:35 19208 api-ms-win-crt-locale-l1-1-0.dll
-a---- 2019/7/8 16:35 27912 api-ms-win-crt-math-l1-1-0.dll
-a---- 2019/7/8 16:35 19720 api-ms-win-crt-process-l1-1-0.dll
-a---- 2019/7/8 16:35 23304 api-ms-win-crt-runtime-l1-1-0.dll
-a---- 2019/7/8 16:35 24840 api-ms-win-crt-stdio-l1-1-0.dll
-a---- 2019/7/8 16:35 24840 api-ms-win-crt-string-l1-1-0.dll
-a---- 2019/7/8 16:35 21256 api-ms-win-crt-time-l1-1-0.dll
-a---- 2019/7/8 16:35 19208 api-ms-win-crt-utility-l1-1-0.dll
-a---- 2019/7/9 15:01 779541 base_library.zip
-a---- 2019/7/9 15:04 306 config.json
-a---- 2019/7/8 16:56 3205632 libcrypto-1_1-x64.dll
-a---- 2019/7/8 16:56 3573880 libGLESv2.dll
-a---- 2019/7/8 16:56 681472 libssl-1_1-x64.dll
-a---- 2019/7/9 15:04 1523306 main.exe
-a---- 2019/7/9 15:04 1029 main.exe.manifest
-a---- 2019/7/9 10:07 625808 MSVCP140.dll
-a---- 2019/7/8 16:35 193024 pyexpat.pyd
-a---- 2019/7/8 16:56 51712 python3.dll
-a---- 2019/7/8 16:35 3745280 python37.dll
-a---- 2019/7/8 16:56 6016632 Qt5Core.dll
-a---- 2019/7/8 16:56 440952 Qt5DBus.dll
-a---- 2019/7/8 16:56 6443640 Qt5Gui.dll
-a---- 2019/7/8 16:56 1338488 Qt5Network.dll
-a---- 2019/7/8 16:56 4010616 Qt5Qml.dll
-a---- 2019/7/8 16:56 3814520 Qt5Quick.dll
-a---- 2019/7/8 16:56 334968 Qt5Svg.dll
-a---- 2019/7/8 16:56 156280 Qt5WebSockets.dll
-a---- 2019/7/8 16:56 5574776 Qt5Widgets.dll
-a---- 2019/7/9 15:04 209 run.log
-a---- 2019/7/8 16:35 19456 select.pyd
-a---- 2019/7/8 16:56 108544 sip.pyd
-a---- 2019/7/8 16:35 1016584 ucrtbase.dll
-a---- 2019/7/8 16:35 1065472 unicodedata.pyd
-a---- 2019/7/8 16:35 87200 VCRUNTIME140.dll
-a---- 2019/7/8 16:35 81920 _bz2.pyd
-a---- 2019/7/8 16:35 125952 _ctypes.pyd
-a---- 2019/7/8 16:35 31744 _hashlib.pyd
-a---- 2019/7/8 16:35 249856 _lzma.pyd
-a---- 2019/7/8 16:35 68608 _socket.pyd
-a---- 2019/7/8 16:35 114176 _ssl.pyd
在conda env中运行时加载的dll:
Process: main.exe Pid: 864
Name Path
kernel32.dll.mui C:\Program Files\WindowsApps\Microsoft.LanguageExperiencePackzh-CN_18362.8.25.0_neutral__8wekyb3d8bbwe\Windows\System32\zh-CN\kernel32.dll.mui
KernelBase.dll.mui C:\Program Files\WindowsApps\Microsoft.LanguageExperiencePackzh-CN_18362.8.25.0_neutral__8wekyb3d8bbwe\Windows\System32\zh-CN\KernelBase.dll.mui
user32.dll.mui C:\Program Files\WindowsApps\Microsoft.LanguageExperiencePackzh-CN_18362.8.25.0_neutral__8wekyb3d8bbwe\Windows\System32\zh-CN\user32.dll.mui
_ctypes.pyd C:\Users\xxx\Idp\dist\main\_ctypes.pyd
_hashlib.pyd C:\Users\xxx\Idp\dist\main\_hashlib.pyd
_socket.pyd C:\Users\xxx\Idp\dist\main\_socket.pyd
_ssl.pyd C:\Users\xxx\Idp\dist\main\_ssl.pyd
_AES.cp37-win_amd64.pyd C:\Users\xxx\Idp\dist\main\Crypto\Cipher\_AES.cp37-win_amd64.pyd
libcrypto-1_1-x64.dll C:\Users\xxx\Idp\dist\main\libcrypto-1_1-x64.dll
libssl-1_1-x64.dll C:\Users\xxx\Idp\dist\main\libssl-1_1-x64.dll
main.exe C:\Users\xxx\Idp\dist\main\main.exe
MSVCP140.dll C:\Users\xxx\Idp\dist\main\MSVCP140.dll
qgif.dll C:\Users\xxx\Idp\dist\main\PyQt5\Qt\plugins\imageformats\qgif.dll
qicns.dll C:\Users\xxx\Idp\dist\main\PyQt5\Qt\plugins\imageformats\qicns.dll
qico.dll C:\Users\xxx\Idp\dist\main\PyQt5\Qt\plugins\imageformats\qico.dll
qjpeg.dll C:\Users\xxx\Idp\dist\main\PyQt5\Qt\plugins\imageformats\qjpeg.dll
qsvg.dll C:\Users\xxx\Idp\dist\main\PyQt5\Qt\plugins\imageformats\qsvg.dll
qtga.dll C:\Users\xxx\Idp\dist\main\PyQt5\Qt\plugins\imageformats\qtga.dll
qtiff.dll C:\Users\xxx\Idp\dist\main\PyQt5\Qt\plugins\imageformats\qtiff.dll
qwbmp.dll C:\Users\xxx\Idp\dist\main\PyQt5\Qt\plugins\imageformats\qwbmp.dll
qwebp.dll C:\Users\xxx\Idp\dist\main\PyQt5\Qt\plugins\imageformats\qwebp.dll
qwindows.dll C:\Users\xxx\Idp\dist\main\PyQt5\Qt\plugins\platforms\qwindows.dll
qwindowsvistastyle.dll C:\Users\xxx\Idp\dist\main\PyQt5\Qt\plugins\styles\qwindowsvistastyle.dll
QtCore.pyd C:\Users\xxx\Idp\dist\main\PyQt5\QtCore.pyd
QtGui.pyd C:\Users\xxx\Idp\dist\main\PyQt5\QtGui.pyd
QtSvg.pyd C:\Users\xxx\Idp\dist\main\PyQt5\QtSvg.pyd
QtWidgets.pyd C:\Users\xxx\Idp\dist\main\PyQt5\QtWidgets.pyd
sip.pyd C:\Users\xxx\Idp\dist\main\PyQt5\sip.pyd
python3.dll C:\Users\xxx\Idp\dist\main\python3.dll
python37.dll C:\Users\xxx\Idp\dist\main\python37.dll
Qt5Core.dll C:\Users\xxx\Idp\dist\main\Qt5Core.dll
Qt5Gui.dll C:\Users\xxx\Idp\dist\main\Qt5Gui.dll
Qt5Svg.dll C:\Users\xxx\Idp\dist\main\Qt5Svg.dll
Qt5Widgets.dll C:\Users\xxx\Idp\dist\main\Qt5Widgets.dll
select.pyd C:\Users\xxx\Idp\dist\main\select.pyd
VCRUNTIME140.dll C:\Users\xxx\Idp\dist\main\VCRUNTIME140.dll
SortDefault.nls C:\Windows\Globalization\Sorting\SortDefault.nls
~FontCache-FontFace.dat C:\Windows\ServiceProfiles\LocalService\AppData\Local\FontCache\~FontCache-FontFace.dat
advapi32.dll C:\Windows\System32\advapi32.dll
bcrypt.dll C:\Windows\System32\bcrypt.dll
bcryptprimitives.dll C:\Windows\System32\bcryptprimitives.dll
C_1252.NLS C:\Windows\System32\C_1252.NLS
cfgmgr32.dll C:\Windows\System32\cfgmgr32.dll
clbcatq.dll C:\Windows\System32\clbcatq.dll
combase.dll C:\Windows\System32\combase.dll
CoreMessaging.dll C:\Windows\System32\CoreMessaging.dll
CoreUIComponents.dll C:\Windows\System32\CoreUIComponents.dll
crypt32.dll C:\Windows\System32\crypt32.dll
cryptbase.dll C:\Windows\System32\cryptbase.dll
cryptsp.dll C:\Windows\System32\cryptsp.dll
d3d11.dll C:\Windows\System32\d3d11.dll
d3d9.dll C:\Windows\System32\d3d9.dll
DataExchange.dll C:\Windows\System32\DataExchange.dll
dcomp.dll C:\Windows\System32\dcomp.dll
igd9dxva64.dll C:\Windows\System32\DriverStore\FileRepository\iigd_dch_base.inf_amd64_b95c9a044993331b\igd9dxva64.dll
dwmapi.dll C:\Windows\System32\dwmapi.dll
DWrite.dll C:\Windows\System32\DWrite.dll
DXCore.dll C:\Windows\System32\DXCore.dll
dxgi.dll C:\Windows\System32\dxgi.dll
gdi32.dll C:\Windows\System32\gdi32.dll
gdi32full.dll C:\Windows\System32\gdi32full.dll
iertutil.dll C:\Windows\System32\iertutil.dll
imm32.dll C:\Windows\System32\imm32.dll
kernel.appcore.dll C:\Windows\System32\kernel.appcore.dll
kernel32.dll C:\Windows\System32\kernel32.dll
KernelBase.dll C:\Windows\System32\KernelBase.dll
locale.nls C:\Windows\System32\locale.nls
mpr.dll C:\Windows\System32\mpr.dll
msasn1.dll C:\Windows\System32\msasn1.dll
msctf.dll C:\Windows\System32\msctf.dll
msvcp_win.dll C:\Windows\System32\msvcp_win.dll
msvcrt.dll C:\Windows\System32\msvcrt.dll
netapi32.dll C:\Windows\System32\netapi32.dll
netutils.dll C:\Windows\System32\netutils.dll
ntdll.dll C:\Windows\System32\ntdll.dll
ntmarta.dll C:\Windows\System32\ntmarta.dll
ole32.dll C:\Windows\System32\ole32.dll
oleaut32.dll C:\Windows\System32\oleaut32.dll
powrprof.dll C:\Windows\System32\powrprof.dll
profapi.dll C:\Windows\System32\profapi.dll
rmclient.dll C:\Windows\System32\rmclient.dll
rpcrt4.dll C:\Windows\System32\rpcrt4.dll
rsaenh.dll C:\Windows\System32\rsaenh.dll
sechost.dll C:\Windows\System32\sechost.dll
SHCore.dll C:\Windows\System32\SHCore.dll
shell32.dll C:\Windows\System32\shell32.dll
shlwapi.dll C:\Windows\System32\shlwapi.dll
srvcli.dll C:\Windows\System32\srvcli.dll
TextInputFramework.dll C:\Windows\System32\TextInputFramework.dll
twinapi.appcore.dll C:\Windows\System32\twinapi.appcore.dll
ucrtbase.dll C:\Windows\System32\ucrtbase.dll
umpdc.dll C:\Windows\System32\umpdc.dll
user32.dll C:\Windows\System32\user32.dll
userenv.dll C:\Windows\System32\userenv.dll
uxtheme.dll C:\Windows\System32\uxtheme.dll
version.dll C:\Windows\System32\version.dll
win32u.dll C:\Windows\System32\win32u.dll
windows.storage.dll C:\Windows\System32\windows.storage.dll
winmm.dll C:\Windows\System32\winmm.dll
winmmbase.dll C:\Windows\System32\winmmbase.dll
WinTypes.dll C:\Windows\System32\WinTypes.dll
ws2_32.dll C:\Windows\System32\ws2_32.dll
wtsapi32.dll C:\Windows\System32\wtsapi32.dll
答案 0 :(得分:4)
假设您并非绝对需要PyQt5版本5.13.0,最简单的修复方法是使用以下命令将PyQt5降级到5.12.2版本:
pip install pyqt5 == 5.12.2
,您的可执行文件将按预期工作。
答案 1 :(得分:2)
升级到Qt5.13后遇到同样的问题。
在pyinstaller github上找到了此解决方案
您需要修改.spec文件并放入以下内容:
from collections import namedtuple
IdxRange = namedtuple('IdxRange', 'min max')
def range_size(idx_range): # ex range_size(IndexRange(0, 10)) = 10
return idx_range.max - idx_range.min
def range_is_contained_in(inner, outer):
return (outer.min <= inner.min <= inner.max <= outer.max)
def trim_pos_dict(pos_dict):
idx_ranges = sorted(map(IdxRange._make, pos_dict), key=range_size, reverse=True)
overlapping_ranges = set()
for target in idx_ranges:
overlapping_ranges.update(x for x in idx_ranges
if x != target and range_is_contained_in(x, target))
trimmed_pos_dict = {k: v for k, v in pos_dict.items() if k not in overlapping_ranges}
return trimmed_pos_dict
答案 2 :(得分:0)
如问题中所述,当在conda控制台中启动捆绑的应用程序时,该应用程序可以正常运行,由static
导出的所有已加载DLL都位于pyinstaller创建的dist目录中。因此,问题在于包含pyqt DLL的路径不在系统的ProcessExplorer
环境中。也许这是pyinstaller的错误。解决方法是手动将程序路径添加到系统PATH
env。
这是我正在使用的代码片段:
PATH
答案 3 :(得分:0)
我注释了文件site-packages\PyQt5\__init__.py
的所有内容,然后重新安装。可以。
我将python3.5
与PyInstaller=3.5
和PyQt5=5.13.0
一起使用。打包的exe在我的计算机上可以运行,但不能在其他计算机上运行。错误消息是:
File "anaconda3\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
File "site-packages\PyQt5\__init__.py", line 41, in <module>
File "site-packages\PyQt5\__init__.py", line 33, in find_qt
ImportError: unable to find Qt5Core.dll on PATH
所以我看到site-packages\PyQt5\__init__.py
(5.13.0)是:
def find_qt():
import os
path = os.environ['PATH']
dll_dir = os.path.dirname(__file__) + '\\Qt\\bin'
if os.path.isfile(dll_dir + '\\Qt5Core.dll'):
path = dll_dir + ';' + path
os.environ['PATH'] = path
else:
for dll_dir in path.split(';'):
if os.path.isfile(dll_dir + '\\Qt5Core.dll'):
break
else:
raise ImportError("unable to find Qt5Core.dll on PATH")
try:
os.add_dll_directory(dll_dir)
except AttributeError:
pass
find_qt()
del find_qt
我认为PyQt5在另一台计算机上找不到PATH,尽管Qt5Core.dll
已经存在于
直接进行项目。所以我注释掉了文件,现在可以了。
答案 4 :(得分:0)
我通过site-packages\PyQt5\__init__.py
中的全部注释为自己解决了此问题
并从旧版QT __init__.py
中添加以下代码:
import os as _os
_path = _os.path.dirname(__file__) + '\\Qt\\bin;' + _os.environ['PATH']
_os.environ['PATH'] = _path