0

I'm trying this basic cython tutorial for the first time. I'm in a conda environment with Python 3.6.6.

Everything works until the point when I want to import the module:

In [1]: import helloworld                                                       
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-39f3e3c18221> in <module>
----> 1 import helloworld

ImportError: dlopen(/Users/billtubbs/cython-examples/helloworld.cpython-36m-darwin.so, 2): Library not loaded: @rpath/libc++abi.1.dylib
  Referenced from: /Users/billtubbs/anaconda/envs/py36/lib/libc++.1.dylib
  Reason: image not found

It seems like a problem with my environment so I tried updating everything:

$ conda update numpy numba pandas scipy scikit-learn pytorch matplotlib statsmodels tensorflow keras cython

I've seen some similar issues but in different circumstances and nothing recent.

How do you start to debug an issue like this?

Steps leading up to this:

helloworld.pyx:

print("Hello World")

setup.py:

from distutils.core import setup
from Cython.Build import cythonize

setup(
    ext_modules = cythonize("helloworld.pyx")
)

As per tutorial:

(py36) $ python --version
Python 3.6.6
(py36) $ python setup.py build_ext --inplace
Compiling helloworld.pyx because it changed.
[1/1] Cythonizing helloworld.pyx
/Users/billtubbs/anaconda/envs/py36/lib/python3.6/site-packages/Cython/Compiler/Main.py:367: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: /Users/billtubbs/cython-examples/helloworld.pyx
  tree = Parsing.p_module(s, pxd, full_module_name)
running build_ext
building 'helloworld' extension
clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -I/Users/billtubbs/anaconda/envs/py36/include -mmacosx-version-min=10.9 -m64 -fPIC -I/Users/billtubbs/anaconda/envs/py36/include -mmacosx-version-min=10.9 -m64 -fPIC -I/Users/billtubbs/anaconda/envs/py36/include/python3.6m -c helloworld.c -o build/temp.macosx-10.9-x86_64-3.6/helloworld.o
clang -bundle -undefined dynamic_lookup -Wl,-rpath,/Users/billtubbs/anaconda/envs/py36/lib -L/Users/billtubbs/anaconda/envs/py36/lib -headerpad_max_install_names -headerpad_max_install_names -mmacosx-version-min=10.9 -lc++ -Wl,-rpath,/Users/billtubbs/anaconda/envs/py36/lib -L/Users/billtubbs/anaconda/envs/py36/lib -Wl,-rpath,/Users/billtubbs/anaconda/envs/py36/lib -L/Users/billtubbs/anaconda/envs/py36/lib -headerpad_max_install_names -headerpad_max_install_names -mmacosx-version-min=10.9 -lc++ -Wl,-rpath,/Users/billtubbs/anaconda/envs/py36/lib -L/Users/billtubbs/anaconda/envs/py36/lib -arch x86_64 build/temp.macosx-10.9-x86_64-3.6/helloworld.o -L/Users/billtubbs/anaconda/envs/py36/lib -o /Users/billtubbs/cython-examples/helloworld.cpython-36m-darwin.so
(py36) $ ls
__pycache__
build
helloworld.c
helloworld.cpython-36m-darwin.so
helloworld.pyx
setup.py

The output of conda list is here if it's needed.

UPDATE

As per @merv suggestion, here is the output of otool that "displays the names and version numbers of the shared libraries that the object file uses":

$ otool -L /Users/billtubbs/anaconda/envs/py36/lib/libc++.1.dylib
/Users/billtubbs/anaconda/envs/py36/lib/libc++.1.dylib:
    @rpath/libc++.1.dylib (compatibility version 1.0.0, current version 1.0.0)
    /usr/lib/libc++abi.dylib (compatibility version 1.0.0, current version 48.0.0)
    @rpath/libc++abi.1.dylib (compatibility version 1.0.0, current version 1.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)
Bill
  • 10,323
  • 10
  • 62
  • 85
  • I tried creating a new (clean) conda environment (Python 3.7.1 as it happened) with only cython installed and the error did not occur. So it may be some thing to do with my py36 environment. A conflict or dependency of some sort perhaps? – Bill Nov 23 '18 at 06:20
  • I don't know enough about MacOS and clang-infrastructure, but having `-lc++` for c-code looks weird to me. It is probably worth looking at and comparing command line parameters of two environments. – ead Nov 23 '18 at 06:32
  • Thanks @ead. I have no idea but `-lc++` did appear in the compiler output when it worked. – Bill Nov 23 '18 at 06:52
  • One place to start is with inspecting the references on the shared libs. For Mac OS X, you can use, for example, `otool -L /Users/billtubbs/anaconda/envs/py36/lib/libc++.1.dylib`. This could help track down what isn't being linked properly. – merv Nov 23 '18 at 18:28
  • Thanks @merv. I added the output of `otool` to the question. Is the fact that current version >= compatible version a good thing? – Bill Nov 24 '18 at 19:09

0 Answers0