Pyinstaller unable to import pylsd while creating exe file

Viewed 839

I am trying to create exe file for a program and I used

    pyinstaller --onefile filename.py 

to create the exe file.

my code uses pylsd but pyinstaller is not able to import the package. when I try to run the exe file it shows:

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 is the name of my code file. does anyone know how this problem might be solved. I have tried adding pylsd to hidden imports in the spec file and tried creating exe using

  pyinstaller --onefile filename.spec

this does not work.

1 Answers

I generated the spec file for my program by using command:

pyi-makespec --onefile final_lines.py

and added lsd.dll binaries, then generated the exe using this command:

pyinstaller --onefile final_lines.spec

the final version of spec file looked lie this:

 # -*- 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 )

my code-file name was final_lines.py. Now the exe works fine. I don't know the fine details but it turns out that you have to add .dll files separately as pyinstaller doesn't include them on its own.

Related