我有这个Python脚本,我想用Pyinstaller变成EXE文件。
这是我的规格文件:
# -*- mode: python ; coding: utf-8 -*-
# work-around for https://github.com/pyinstaller/pyinstaller/issues/4064
import distutils
if distutils.distutils_path.endswith('__init__.py'):
distutils.distutils_path = os.path.dirname(distutils.distutils_path)
block_cipher = None
a = Analysis(['hello-world.py'],
pathex=['C:\\Users\\Testuser\\workspace\\hello-world'],
binaries=[],
datas=[ ('lib/*', '.') ],
hiddenimports=[
'distutils',
'scipy._lib.messagestream',
'sklearn.neighbors.typedefs',
'sklearn.neighbors.quad_tree',
'sklearn.tree',
'sklearn.tree._utils'
],
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='hello-world',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=True )
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
upx_exclude=[],
name='hello-world')
但是在Win 10 64位虚拟机中运行它时出现此错误:
Traceback (most recent call last):
File "hello-world.py", line 11, in <module>
File "c:\users\testuser\workspace\hello-world\.venv\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
File "site-packages\sklearn\__init__.py", line 76, in <module>
File "c:\users\testuser\workspace\hello-world\.venv\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
File "site-packages\sklearn\base.py", line 16, in <module>
File "c:\users\testuser\workspace\hello-world\.venv\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
File "site-packages\sklearn\utils\__init__.py", line 13, in <module>
File "c:\users\testuser\workspace\hello-world\.venv\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
File "site-packages\scipy\sparse\__init__.py", line 230, in <module>
File "c:\users\testuser\workspace\hello-world\.venv\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
File "site-packages\scipy\sparse\csr.py", line 13, in <module>
ImportError: DLL load failed: The specified module could not be found.
EXE在我使用它构建的计算机上运行良好。将文件夹复制到VM中会导致上述错误。我不确定错误所指向的DLL。
我猜想它与错误中的路径有关,因为c:\users\testuser\workspace\hello-world
在VM中不存在。我在这里没有Pyinstaller选项吗?生成的EXE是否应该引用我的旧路径?
答案 0 :(得分:1)
那是因为我没有安装Numpy和SciPy的MKL版本。
安装它们后,我将丢失的DLL文件添加到了规范文件中:
datas=[
('lib/*', '.'),
('.venv/Lib/site-packages/numpy/DLLs/mkl_intel_thread.dll', '.'),
('.venv/Lib/site-packages/numpy/DLLs/mkl_core.dll', '.'),
('.venv/Lib/site-packages/numpy/DLLs/mkl_def.dll', '.'),
('.venv/Lib/site-packages/numpy/DLLs/libiomp5md.dll', '.')
],
现在它可以在我的虚拟机中工作了。
希望这对某人有帮助!