You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Undefined symbol : pfnc_inq_vardimid during import netCDF4 #1417
netCDF4-python: 1.7.2 (same result with pip install and from source via pip install .)
netcdf-c: 4.9.3 (custom build, with nc_complex enabled)
HDF5: 1.14.6
OS: Rocky Linux 8.10
Trying to install netcdf4-python from : pip install netCDF4 or from source code : pip install . I get the following error when trying to import netCDF4 in python although there is no error during the installation :
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/fparadis/pyenv/lib/python3.11/site-packages/netCDF4/__init__.py", line 3, in <module>
from ._netCDF4 import *
ImportError: /home/fparadis/pyenv/lib/python3.11/site-packages/netCDF4/_netCDF4.cpython-311-x86_64-linux-gnu.so: undefined symbol: pfnc_inq_vardimid
From my current understanding, these symbols are defined inside nc_complex which should be automatically added during the installation of netCDF4-python. However, I've also tried to install manually nc_complex and link them using LD_LIBRARY_PATH but to no success. Using nm -D, I can see the symbols pfnc_inq_vardimid is correctly defined in libnc_complex.so.
As I don't need nc_complex in my installation, I was wondering if it is either possible to deactivate nc_complex or how to correctly link the symbols to it.
When you say 'netcdf-c: 4.9.3 (custom build, with nc_complex enabled)' do you mean that it's a modified version of the C-lib with nc_complex included? If so, I suspect that there is a conflict between the two versions of nc_complex (the one in the C lib and the one included in the python module).
I had the same issue, with at least 1.7.2 and 1.7.4 and fixed it with two 'dirty' patches.
Since I am no expert with python, cython, numpy, hdf5 or netcdf, someone with
deeper knowledge might want to fix it properly.
First one removes 'inline' from the two functions AND makes them invisible, if a
compile unit defines 'NO_INLINE_FUNCTIONS', otherwise the linker would complain about
multiple symbol definitions.
Second patch defines 'NO_INLINE_FUNCTIONS' before including the header.
--- external/nc_complex/include/nc_complex/nc_complex.h.original
+++ external/nc_complex/include/nc_complex/nc_complex.h
@@ -242,14 +242,16 @@
int* nattsp
);
+#ifndef NO_INLINE_FUNCTIONS
// NOLINTBEGIN(modernize-use-nullptr)
-NC_COMPLEX_EXPORT inline int pfnc_inq_varndims(int ncid, int varid, int* ndimsp) {
+NC_COMPLEX_EXPORT int pfnc_inq_varndims(int ncid, int varid, int* ndimsp) {
return pfnc_inq_var(ncid, varid, NULL, NULL, ndimsp, NULL, NULL);
}
-NC_COMPLEX_EXPORT inline int pfnc_inq_vardimid(int ncid, int varid, int* dimidsp) {
+NC_COMPLEX_EXPORT int pfnc_inq_vardimid(int ncid, int varid, int* dimidsp) {
return pfnc_inq_var(ncid, varid, NULL, NULL, NULL, dimidsp, NULL);
}
// NOLINTEND(modernize-use-nullptr)
+#endif
NC_COMPLEX_EXPORT int pfnc_def_var_chunking(
int ncid, int varid, int storage, const size_t* chunksizesp
Traceback (most recent call last):
File "/tmp/build-bot/netcdf-1.7.4/test/./run_all.py", line 2, in <module>
from netCDF4 import __hdf5libversion__,__netcdf4libversion__,__version__, Dataset
File "/tmp/build-bot/netcdf-1.7.4/build/lib.linux-x86_64-cpython-314/netCDF4/__init__.py", line 11, in <module>
from ._netCDF4 import *
ImportError: /tmp/build-bot/netcdf-1.7.4/build/lib.linux-x86_64-cpython-314/netCDF4/_netCDF4.cpython-314-x86_64-linux-gnu.so: undefined symbol: pfnc_inq_vardimid
while with the patches its
netcdf4-python version: 1.7.4
HDF5 lib version: 2.2.0
netcdf lib version: 4.10.1
numpy version 2.5.3
cython version 3.3.0
s...................................................................s...........................s..........compressed lossy with shuffle and standard quantization = 187676 max err = 0.00024412745124813284
compressed lossy with shuffle and alternate quantization = 155270 max err = 0.00048827517723559755
compressed lossy with shuffle and alternate quantization = 162934 max err = 0.0002441371616678234
......s.
----------------------------------------------------------------------
Ran 115 tests in 113.330s
OK (skipped=4)
Activity
jswhit commentedon Aug 5, 2025
@ZedThree ?
jswhit commentedon Aug 5, 2025
When you say 'netcdf-c: 4.9.3 (custom build, with nc_complex enabled)' do you mean that it's a modified version of the C-lib with nc_complex included? If so, I suspect that there is a conflict between the two versions of nc_complex (the one in the C lib and the one included in the python module).
ZedThree commentedon Aug 6, 2025
I thought that we build
nc_complexas part of the Cython build?netcdf4-python/setup.py
Lines 428 to 437 in 57b9a80
So I don't think you need to have built it separately.
ocefpaf commentedon Aug 6, 2025
Also, I cannot reproduce that with the built wheel. Your
pip installis probably from source, right? If so, something is amiss with your build.Cor0n4V1rus commentedon Sep 15, 2026
I had the same issue, with at least 1.7.2 and 1.7.4 and fixed it with two 'dirty' patches.
Since I am no expert with python, cython, numpy, hdf5 or netcdf, someone with
deeper knowledge might want to fix it properly.
First one removes 'inline' from the two functions AND makes them invisible, if a
compile unit defines 'NO_INLINE_FUNCTIONS', otherwise the linker would complain about
multiple symbol definitions.
Second patch defines 'NO_INLINE_FUNCTIONS' before including the header.
For the record (with gcc 16.2.0) :
Without my patches, building it with
and testing it with
yields
while with the patches its