pyomeca / ezc3d

Easy to use C3D reader/writer for C++, Python and Matlab
https://pyomeca.github.io/Documentation/ezc3d/index.html
MIT License
145 stars 46 forks source link

Pyinstaller and ezc3d #319

Closed DocVi closed 7 months ago

DocVi commented 7 months ago

Hi,

I have been using the ezc3d with python. My code works well locally but I need to package it in one single exe file.

I do that using pyinstaller main.py --onefile --name Theia-Tools.exe --hidden-import ezc3d. I tried to use add-data as well to add the dll to a different folder. Unfortunately, in all cases when I run the exe locally I get an error immediately (see picture).

DLL

I have been using pynstaller many times and it always works but not this time.

Any help would be great.

Thanks

Vincent

pariterre commented 7 months ago

Dear @DocVi

The ezc3d is primarily a C++ library that I binded to Python using swig. This basically means that the underlying code that reads the data, is not in a .py file, but is compiled into a dynamic library (DLL on Windows).

Dynamic libraries can unfortunately be extremely tricky to deal with, especially on Windows. That is the reason why we use virtual environment such as Anaconda in the first place. By trying to wrap ezc3d in your installer, you try to encapsulate the complexity of dynamicl libraries in a simple manner, which may or may not work, depending on chance.

What are your potential solutions: 1) If the host computer of the .exe has access to internet, install ezc3d using anaconda. 2) If the host computer does not have access to internet, you can try to compile ezc3d on that computer. 3) If you are certain the host computer shares spec with another computer (same version of windows, both being 64-bits, etc.) then you can use the compiled version from that computer.

Currenlty, what you are trying to do is 3). Which again can be okay, as long as the host computer has the same configuration as the one you have ezc3d installed. That said, I suspect pyinstaller does not include the DLL file. The reason I am saying that is "_ezc3d" is a dll file that must be found by your exe.

The final solution, which is not a single file solution (which honestly I don't think is possible anyway), is to copy "_ezc3d.dll" next to the ".exe" file.

Hope this helps!

DocVi commented 7 months ago

Thanks. I see. I am using the same computer right now. I see ezc3d.dll but not _ezc3d.dll in Miniconda3\envs\theia-tools\Library\bin Is it just a matter of renaming it?

pariterre commented 7 months ago

Nope, _ezc3d is in the installed folder of ezc3d in the Lib\site-packages folder

DocVi commented 7 months ago

Ok. Thanks. I saw that one but it is not a dll or at least it does not have the .dll extension I will try adding that one to the dir

DocVi commented 7 months ago

Good news. It actually works with onedir and onefile. After some investigation I realized that my pyinstaller that I was running was not the one from my conda environment. Good to know and good to check! :)