简体   繁体   English

不能在Pyinstaller的exe中使用lightgbm.dll

[英]Cannot use lightgbm.dll in Pyinstaller's exe

I am trying to convert my code into an exe using pyinstaller spec. 我试图使用pyinstaller规范将我的代码转换为exe。 I ran pyinstaller with the following command: 我使用以下命令运行pyinstaller:

pyinstaller --clean --add-data lib_lightgbm.dll;\compile orca.spec

The exe fails with the error: exe失败并出现错误:

main__.PyInstallerImportError: Failed to load dynlib/dll 
'C:\\Users\\...\\lightgbm\\../compile\\lib_lightgbm.dll'. Most probably this 
dynlib/dll was not found when the application was frozen.

I have tried adding lightgbm.dll through binaries, but didnt work. 我试过通过二进制文件添加lightgbm.dll,但没有用。 I also tried manually copying it to the destination after the exe is created. 我还尝试在创建exe后手动将其复制到目标。 That didnt work either. 那也没有用。 Most of the questions about pyinstaller and lib_lightgbm.dll failed to answer my issue. 关于pyinstaller和lib_lightgbm.dll的大多数问题未能解决我的问题。 Can someone please suggest a solution? 有人可以建议一个解决方案? I am at my wits end at the moment. 我此刻正处于斗智斗勇的境地。

Here is my spec file: 这是我的spec文件:

# -*- mode: python -*-
import sys
sys.setrecursionlimit(5000)

block_cipher = None


a = Analysis(['mycode.py'],
             pathex=['C:\\mycode\\source code'],
             binaries=[],
             datas=[],
             hiddenimports=['cython', 'sklearn', 'sklearn.feature_extraction','sklearn.pipeline', 'sklearn.ensemble', 'sklearn.neighbors.typedefs', 'sklearn.neighbors.quad_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='mycode',
          debug=True,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          console=True )
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=False,
               upx=True,
               name='mycode')

When you build from a spec file, those options cannot be changed. 从spec文件构建时,无法更改这些选项。

so either add the tuple to the datas section, or ommit the spec file and use all the parameters for pyinstaller 因此无论是元组添加到datas部分,或ommit规范文件,并使用所有参数pyinstaller

I'm not 100% sure this is the fix, but there should be something in your datas section of you spec file. 我不是100%确定这是修复,但你的spec文件的datas部分应该有一些东西。 So I'd investigate that. 所以我会调查一下。 you can also build from a spec file using pyinstaller <spec file here> when you're done editing it. 您也可以在编辑完成后使用pyinstaller <spec file here>从spec文件构建。

https://pyinstaller.readthedocs.io/en/stable/spec-files.html https://pyinstaller.readthedocs.io/en/stable/spec-files.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM