"dynlib/dll was no found when the application was frozen" when I make a .exe file using pyinstaller, because of pylibmtx the error was occurred

Viewed 7378

enter image description here

when I enter image description here

I am struggling to make .exe files. the error message was shown that it has problem on number 9 line, so I checked my code. there were imported library "pylibdmtx" which is to decode the datamatrix.

so I tried to remove all about that library with other related attributes and then it was fine. I tried to figure that issue out for troubleshooting, but I couldn't find it. so I finally ask my issue to you.

I uploaded captures of my problem

thanks.

5 Answers

Maybe little late, but I'll share this information is anyone else has issue with this:

found here.

In the bootloader we call SetDllDirectory with our extraction path. For some reason this seems to prevent loading a dll from the current directory. If SetDllDirectory is called with a Null argument to reset the dll search path loading a dll from the current directory works.

Example based on vlc and the libvlc.dll.

Doesn't work:

import ctypes
import os

os.chdir('C:\\Program Files\\VideoLan\\VLC\\')
print(ctypes.CDLL('libvlc.dll'))

Works:

import ctypes
import os

ctypes.windll.kernel32.SetDllDirectoryW(None)

os.chdir('C:\\Program Files\\VideoLan\\VLC\\')
print(ctypes.CDLL('libvlc.dll'))

So if your code loads external DLL files with ctypes, make sure to add this line before you load your DLL (tested under Windows, not sure about other OSes)

ctypes.windll.kernel32.SetDllDirectoryW(None)

It's late , but I must say what fixed a problem that took 3 days to solve, simply installing c++ redistributable and restart machine solved my probelm

Freezers such as pyinstaller and cx_Freeze are not able to find libraries loaded using ctypes. pylibdmtx exposes these binary dependencies in pylibdmtx.EXTERNAL_DEPENDENCIES - a list of instances of ctypes.CDLL. You can get pyinstaller to include these in the freeze using a pyinstaller spec file (example).

You might have to explicitly include needed the DLL files when creating the executable with Pyinstaller. Assuming the required DLL file is xyz.dll, and the python script is myscript.py, you can include the DLL like this:

> pyinstaller --add-binary xzy.dll;. --onefile myscript.py

This places the DLL in the base path within the created executable file

Bundle the relevant version of MCVCP*.DLL with your program to satisfy the needs of that DLL in question.

Related