gpt4 book ai didi

python - Pyinstaller 在创建 exe 文件时无法导入 pylsd

转载 作者:太空宇宙 更新时间:2023-11-03 11:59:53 25 4
gpt4 key购买 nike

我正在尝试为程序创建 exe 文件,我使用了

    pyinstaller --onefile filename.py 

创建exe文件。

我的代码使用 pylsd,但 pyinstaller 无法导入包。当我尝试运行它显示的 exe 文件时:

Traceback (most recent call last):
File "final_lines.py", line 4, in <module>
from pylsd.lsd import lsd
File "c:\users\yash.sharma\appdata\local\programs\python\python36\lib\site-
packages\PyInstaller\loader\pyimod03_importers.py", line 631, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\pylsd\__init__.py", line 8, in <module>
File "c:\users\yash.sharma\appdata\local\programs\python\python36\lib\site-
packages\PyInstaller\loader\pyimod03_importers.py", line 631, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\pylsd\lsd.py", line 8, in <module>
File "c:\users\yash.sharma\appdata\local\programs\python\python36\lib\site-
packages\PyInstaller\loader\pyimod03_importers.py", line 631, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\pylsd\bindings\__init__.py", line 8, in <module>
File "c:\users\yash.sharma\appdata\local\programs\python\python36\lib\site-
packages\PyInstaller\loader\pyimod03_importers.py", line 631, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\pylsd\bindings\lsd_ctypes.py", line 56, in <module>
ImportError: Cannot load dynamic library. Did you compile LSD?
[13252] Failed to execute script final_lines

final_lines.py 是我的代码文件的名称。有谁知道如何解决这个问题。我尝试将 pylsd 添加到规范文件中的隐藏导入,并尝试使用

创建 exe
  pyinstaller --onefile filename.spec

这行不通。

最佳答案

我使用命令为我的程序生成了规范文件:

pyi-makespec --onefile final_lines.py

并添加 lsd.dll 二进制文件,然后使用此命令生成 exe:

pyinstaller --onefile final_lines.spec

spec 文件的最终版本看起来是这样的:

 # -*- mode: python -*-

block_cipher = None


a = Analysis(['final_lines.py'],
pathex=['C:\\Users\\yash.sharma\\Desktop\\text\\obj'],
binaries= [('C:\\Users\\yash.sharma\\AppData\\Local\\Programs\\Python\\Python36\\Lib\\site-packages\\pylsd\\lib\\win32\\x64\\lsd.dll', '.')],
datas=[],
hiddenimports=['C:\\Users\\yash.sharma\\AppData\\Local\\Programs\\Python\\Python36\\Lib\\site-packages\\pylsd\\bindings\\lsd_ctypes.py'],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher)

pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)

exe = EXE(pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
name='final_lines',
debug=False,
strip=False,
upx=True,
runtime_tmpdir=None,
console=True )

我的代码文件名为 final_lines.py。现在exe工作正常。我不知道详细信息,但事实证明您必须单独添加 .dll 文件,因为 pyinstaller 本身不包含它们。

关于python - Pyinstaller 在创建 exe 文件时无法导入 pylsd,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52288690/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com