mzechmeister / serval

calculate radial velocities from stellar spectra
MIT License
36 stars 9 forks source link

load_library - OSError: no file with expected extension #37

Closed mzechmeister closed 3 years ago

mzechmeister commented 3 years ago

The readme suggests compiling with

gcc -c  -Wall -O2 -ansi -pedantic -fPIC cbspline.c; gcc -o cbspline.so -shared cbspline.o

The suffix .so is common in unix for shared library. However, with Mac OS the following error occurs

Traceback (most recent call last):
  File "serval/src/serval.py", line 39, in <module>
    import cspline as spl
  File "serval/src/cspline.py", line 22, in <module>
    _cbspline = np.ctypeslib.load_library(os.path.join(os.path.dirname(__file__), 'cbspline'), '.')
  File ".../site-packages/numpy/ctypeslib.py", line 155, in load_library
    raise OSError("no file with expected extension")
OSError: no file with expected extension

Currently, np.ctypeslib.load_library is used in https://github.com/mzechmeister/serval/blob/1542d0b267bea08b13a807aebf20374675946494/src/cspline.py#L22 which guesses the extension in
https://github.com/numpy/numpy/blob/92ebe1e9a6aeb47a881a1226b08218175776f9ea/numpy/ctypeslib.py#L130 and finally uses ctypes.cdll in L150.

On Mac OS python -c "from numpy.distutils.misc_util import get_shared_lib_extension; print(get_shared_lib_extension())" results in .dylib.

Including the suffix .so explicitly seems to solve the problem. Since the purpose of np.ctypeslib.load_library is mainly to find the suffix, is not used anymore, just ctypes.cdll or ctypes.CDLL might be used.

mzechmeister commented 3 years ago

Final solution: https://github.com/mzechmeister/serval/blob/a5551f02ea20d5a63f4f5e41be1199f2eae5364a/src/cspline.py#L22