nucleic / kiwi

Efficient C++ implementation of the Cassowary constraint solving algorithm
https://kiwisolver.readthedocs.io/en/latest/
Other
692 stars 88 forks source link

PyInstaller executable with matplotlib cannot find _cext DLL #168

Open mapcreatorGuus opened 1 year ago

mapcreatorGuus commented 1 year ago

I used PyInstaller 5.13.2 to create an executable that uses Matplotlib 3.7.3 (and therefore also Kiwisolver 1.4.5). This creates an executable that runs fine on my developer computer, but crashes on the _cext DLL import on another machine:

image

I'm not sure what other information I can provide that could be useful here. Let me know if you need to know anything else.

MatthieuDartiailh commented 1 year ago

I have no personal experience with PyInstaller but is it possible it somehow forgot to package the compiled dll for kiwi ? That's how I read error message. You should have both a _cext.pyi and a .pyd in your install, PyInstaller may have packaged only the .pyi.

mapcreatorGuus commented 1 year ago

As far as my expertise goes in this regard, it seems to be the other way around: only the pyd (_cext.cp311-win_amd64.pyd) is present.

I'm not entirely sure what to try next and if this is even the problem of kiwisolver or perhaps of PyInstaller instead. This paragraph on the pyinstaller wiki may be related: https://pyinstaller.org/en/v5.13.2/when-things-go-wrong.html#listing-hidden-imports. It seems that, generally, pyinstaller leaves it up to other packages to contribute their own hooks so that packages can be frozen properly, but this could also be an issue on their end.

MatthieuDartiailh commented 1 year ago

Kiwi has no hidden imports. Could you post the content of the kiwi package in the install created by PyInstaller ?

mapcreatorGuus commented 1 year ago

Just to clarify: I cannot completely view the results of builds as I run PyInstaller with --onefile, which creates a single self-contained exectuable. My findings about the package contents regard those when I use PyInstaller without the --onefile option.

That being said, the installed package contains a kiwisolver folder with inside it only the file "_cext.cp311-win_amd64.pyd".

Another perhaps useful thing me and a colleague discovered in the meantime is the following: when I place msvcp140.dll next to my executable, it does run fine. This suggests that that dll is not properly included when freezing my project with PyInstaller.

MatthieuDartiailh commented 1 year ago

This is weird on several level:

mapcreatorGuus commented 1 year ago

I'm not really sure how to proceed with this. My personal runtime problem is solved by manually including the msvcp140.dll in the PyInstaller build, but I do not think that is a satisfying solution for this situation.

The way I see it now the desired solution would be either of the following:

But maybe I'm overlooking something, let me know what you think. Anyway, I really appreciate your help so far :)