netcdf4-python icon indicating copy to clipboard operation
netcdf4-python copied to clipboard

Import Problem with netCDF4 DLL and pyinstaller, I do not know what to do

Open mtsamorim opened this issue 1 year ago • 3 comments

Hello guys, I recently created a program that uses several libraries related in some way to geology or geospatial data, and the files that my program reads are .nc or .nc4, it is running perfectly if I run it myself using a command like python program.py So I decided to create an executable of it with pyinstaller and at first everything seemed to go well, the program's interface opens perfectly, but when it gets to the part where it appears that it uses netCDF4, which is the part that reads .nc4 files, some kind of error which I am leaving below.

Exception in Tkinter callback Traceback (most recent call last): File "tkinter_init.py", line 1892, in call File "interface.py", line 251, in File "interface.py", line 603, in select_variables File "interface.py", line 49, in init File "interface.py", line 75, in read_variables_from_netcdf File "xarray\backends\api.py", line 541, in open_dataset File "xarray\backends\netCDF4_.py", line 578, in open_dataset File "xarray\backends\netCDF4_.py", line 349, in open File "PyInstaller\loader\pyimod02_importers.py", line 419, in exec_module File "netCDF4_init_.py", line 31, in ImportError: DLL load failed while importing netCDF4: The specified module could not be found.

I've tried everything when I can, I've already passed several variables on the pyinstaller command line when generating the executable, but even so, when it gets to this part of the program, it gives me this error, would anyone have any idea what it could be and how to fix it? ? I even went so far as to create another environment in conda to install everything again to see if the problem was the previous environment but it continues, I will be extremely grateful if someone helps me with this persistent and annoying error that only happens in the program's executable, as the code is working perfectly

mtsamorim avatar Apr 08 '24 18:04 mtsamorim

I am not familiar with pyinstaller, but I imagine it's tricky to get it to work correctly when there are many dependencies with C extensions that link external C libraries.

jswhit avatar Apr 10 '24 22:04 jswhit

I am not familiar with pyinstaller, but I imagine it's tricky to get it to work correctly when there are many dependencies with C extensions that link external C libraries.

Could this be it? I really needed this executable, would you have any idea of another way to create an executable or even a family library?

mtsamorim avatar Apr 12 '24 12:04 mtsamorim

how about a conda environment bundled in a container (like apptainer)?

jswhit avatar Apr 12 '24 18:04 jswhit