Python pyinstaller ImportError:DLL加载失败-仅在某些PC上';s
我通过运行以下命令,使用pyinstaller创建了一个exe:Python pyinstaller ImportError:DLL加载失败-仅在某些PC上';s,python,python-3.x,pyinstaller,Python,Python 3.x,Pyinstaller,我通过运行以下命令,使用pyinstaller创建了一个exe: pyinstaller app_proto.spec app_proto.spec如下所示: # -*- mode: python ; coding: utf-8 -*- block_cipher = None a = Analysis(['app_proto.py'], pathex=['C:\\Users\\user01\\Documents\\GitHub Repos\\app\\src']
pyinstaller app_proto.spec
app_proto.spec如下所示:
# -*- mode: python ; coding: utf-8 -*-
block_cipher = None
a = Analysis(['app_proto.py'],
pathex=['C:\\Users\\user01\\Documents\\GitHub Repos\\app\\src'],
binaries=[],
datas=[('C:/Users/user01/AppData/Local/Programs/Python/Python38/Lib/site-packages/dask/dask.yaml', 'dask' )],
hiddenimports=['dask'],
hookspath=[],
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='app_proto',
debug=True,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=True )
a.datas +=[('./icons/application-export.png','C:\\Users\\user01\\Documents\\GitHub Repos\\app\\src\\icons\\application-export.png','DATA')]
a.datas +=[('./icons/application-import.png','C:\\Users\\user01\\Documents\\GitHub Repos\\app\\src\\icons\\application-import.png','DATA')]
a.datas +=[('./icons/application-wave.png','C:\\Users\\user01\\Documents\\GitHub Repos\\app\\src\\icons\\application-wave.png','DATA')]
a.datas +=[('./icons/arrow-out.png','C:\\Users\\user01\\Documents\\GitHub Repos\\app\\src\\icons\\arrow-out.png','DATA')]
a.datas +=[('./icons/border-bottom-thick.png','C:\\Users\\user01\\Documents\\GitHub Repos\\app\\src\\icons\\border-bottom-thick.png','DATA')]
a.datas +=[('./icons/border-left.png','C:\\Users\\user01\\Documents\\GitHub Repos\\app\\src\\icons\\border-left.png','DATA')]
a.datas +=[('./icons/border-right.png','C:\\Users\\user01\\Documents\\GitHub Repos\\app\\src\\icons\\border-right.png','DATA')]
a.datas +=[('./icons/chart--plus.png','C:\\Users\\user01\\Documents\\GitHub Repos\\app\\src\\icons\\chart--plus.png','DATA')]
a.datas +=[('./icons/desktop.ini','C:\\Users\\user01\\Documents\\GitHub Repos\\app\\src\\icons\\desktop.ini','DATA')]
a.datas +=[('./icons/edit-list-rtl.png','C:\\Users\\user01\\Documents\\GitHub Repos\\app\\src\\icons\\edit-list-rtl.png','DATA')]
a.datas +=[('./icons/folder-open-document.png','C:\\Users\\user01\\Documents\\GitHub Repos\\app\\src\\icons\\folder-open-document.png','DATA')]
a.datas +=[('./icons/marker.png','C:\\Users\\user01\\Documents\\GitHub Repos\\app\\src\\icons\\marker.png','DATA')]
a.datas +=[('./icons/minus-circle.png','C:\\Users\\user01\\Documents\\GitHub Repos\\app\\src\\icons\\minus-circle.png','DATA')]
a.datas +=[('./icons/minus.png','C:\\Users\\user01\\Documents\\GitHub Repos\\app\\src\\icons\\minus.png','DATA')]
a.datas +=[('./icons/report-word.png','C:\\Users\\user01\\Documents\\GitHub Repos\\app\\src\\icons\\report-word.png','DATA')]
a.datas +=[('./icons/script-attribute-y.png','C:\\Users\\user01\\Documents\\GitHub Repos\\app\\src\\icons\\script-attribute-y.png','DATA')]
a.datas +=[('./icons/system-monitor.png','C:\\Users\\user01\\Documents\\GitHub Repos\\app\\src\\icons\\system-monitor.png','DATA')]
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
upx_exclude=[],
name='app_proto')
在某些PC上,在启用调试的情况下,使用--onedir
模式运行exe时,会显示以下输出:
[2020] LOADER: Running pyi_rth_mplconfig.py
[2020] LOADER: Running pyi_rth_mpldata.py
[2020] LOADER: Running pyi_rth_pyqt5.py
[2020] LOADER: Running app_proto.py
Traceback (most recent call last):
File "src\app_proto.py", line 7, in <module>
File "c:\users\user01\appdata\local\programs\python\python38\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, in exec_module
File "src\pyinstallerimports\__init__.py", line 1, in <module>
File "c:\users\user01\appdata\local\programs\python\python38\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, in exec_module
File "site-packages\cchardet\__init__.py", line 1, in <module>
ImportError: DLL load failed while importing _cchardet: The specified module could not be found.
[2020] Failed to execute script app_proto
[2020] LOADER: OK.
[2020] LOADER: Cleaning up Python interpreter.
[2020]加载程序:运行pyi\u rth\u mplconfig.py
[2020]加载器:运行pyi_rth_mpldata.py
[2020]加载器:运行pyi_rth_pyqt5.py
[2020]加载器:运行app_proto.py
回溯(最近一次呼叫最后一次):
文件“src\app_proto.py”,第7行,在
exec_模块中的文件“c:\users\user01\appdata\local\programs\python38\lib\site packages\PyInstaller\loader\pyimod03_importers.py”,第623行
文件“src\pyinstallerimports\\uuuu init\uuuuu.py”,第1行,在
exec_模块中的文件“c:\users\user01\appdata\local\programs\python38\lib\site packages\PyInstaller\loader\pyimod03_importers.py”,第623行
文件“site packages\cchardet\\uuuuu init\uuuuuuu.py”,第1行,在
导入错误:导入时DLL加载失败\u硬件:找不到指定的模块。
[2020]无法执行脚本app_proto
[2020]加载器:好的。
[2020]加载程序:清理Python解释器。
正如问题中提到的,exe可以在少数几台PC上运行(有些PC以前从未安装过python,如果有必要的话)。在exe的目录中有一个名为
cchardet
的文件夹,其中包含.pyd文件\u cchardet
有人知道如何解决这个问题吗?我在使用Python3.7时遇到了与cchardet相同的错误。更新Visual C++解决了这个问题。 试试这些步骤-