title: Problem loading dylib libraries in python with macOS
body: <p>I know that similar questions have been asked many times, but I could not find a solution that worked in my case. I am a newbie with macOS, and for sure I'm missing something on how dynamic linking works in Mac. I must import a dylib library in python, which in turn should import another library.
  Here are the relevant files, environment variables and parts of the code:</p>
  
  <pre><code>$ echo $DYLD_LIBRARY_PATH 
  /usr/local/lib/:/Developer/NVIDIA/CUDA-10.2/lib
  
  $ ls /Developer/NVIDIA/CUDA-10.2/lib/libcurand.*
  /Developer/NVIDIA/CUDA-10.2/lib/libcurand.10.dylib
  /Developer/NVIDIA/CUDA-10.2/lib/libcurand.dylib
  
  $ ls -al /usr/local/lib/libcurand.*
  lrwxr-xr-x  1 golosio  admin  50 Feb 24 09:55 /usr/local/lib/libcurand.10.dylib -&gt; /Developer/NVIDIA/CUDA-10.2/lib/libcurand.10.dylib
  lrwxr-xr-x  1 golosio  admin  47 Feb 24 09:55 /usr/local/lib/libcurand.dylib -&gt; /Developer/NVIDIA/CUDA-10.2/lib/libcurand.dylib
  
  $ ls -al /usr/local/lib/libneurongpu.*
  -rwxr-xr-x  1 root  admin  4496 Feb 24 10:32 /usr/local/lib/libneurongpu.0.dylib
  lrwxr-xr-x  1 root  admin    20 Feb 24 10:32 /usr/local/lib/libneurongpu.dylib -&gt; libneurongpu.0.dylib
  -rwxr-xr-x  1 root  admin   953 Feb 24 10:32 /usr/local/lib/libneurongpu.la
  
  $ python
  
  &gt;&gt;&gt; import ctypes
  
  &gt;&gt;&gt; lib_path="/usr/local/lib/libneurongpu.dylib"
  
  &gt;&gt;&gt; _neurongpu=ctypes.CDLL(lib_path)
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py", line 366, in __init__
      self._handle = _dlopen(self._name, mode)
  OSError: dlopen(/usr/local/lib/libneurongpu.dylib, 6): Library not loaded: @rpath/libcurand.10.dylib
    Referenced from: /usr/local/lib/libneurongpu.dylib
    Reason: image not found
  </code></pre>
  
  <p>I would like to understand not only what I should do to import the libraries, but also why what I am doing is not working.</p>