0

On Macos, I have set DYLD_LIBRARY_PATH this way:

export DYLD_LIBRARY_PATH=/Applications/PicoScope6.app/Contents/Resources/lib

If I run those two lines in IPython, it works :

from ctypes import cdll
cdll.LoadLibrary("libps2000a.dylib")

but I run them in the standard python interpreter, I get :

$ /usr/bin/python
Python 2.7.10 (default, Feb  7 2017, 00:08:15)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from ctypes import cdll
>>> cdll.LoadLibrary("libps2000a.dylib")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py", line 443, in LoadLibrary
    return self._dlltype(name)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py", line 365, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: dlopen(libps2000a.dylib, 6): image not found

EDIT1 : I think it has something to with the Python provided by Apple because with /usr/local/bin/python2 (provided by the brew utility), it works :

$ /usr/local/bin/python2
Python 2.7.13 (default, Jul 18 2017, 09:17:00)
[GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.42)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from ctypes import cdll
>>> cdll.LoadLibrary("libps2000a.dylib")
<CDLL 'libps2000a.dylib', handle 7f8838d01f80 at 10b438f50>

EDIT2 : I have the same pb. with the DYLD_LIBRARY_PATH variable as with the LD_LIBRARY_PATH variable

What can I do to "tell" the "Apple Python" to "see" the DYLD_LIBRARY_PATH ?

SebMa
  • 4,037
  • 29
  • 39

1 Answers1

1

On MacOS X it is DYLD_LIBRARY_PATH not LD_LIBRARY_PATH.

See the man page for dyld for details on environment variables you can set which affect the dynamic linker.

Graham Dumpleton
  • 57,726
  • 6
  • 119
  • 134
  • I have the same pb. with the `DYLD_LIBRARY_PATH` variable – SebMa Aug 28 '17 at 12:46
  • Have you verified it is set correctly in the process after it has started by using ``import os; os.environ['DYLD_LIBRARY_PATH']``? – Graham Dumpleton Oct 18 '17 at 19:46
  • `echo $DYLD_LIBRARY_PATH` says `/Applications/PicoScope6.app/Contents/Resources/lib` but python says `KeyError: 'DYLD_LIBRARY_PATH'` – SebMa Oct 19 '17 at 12:00
  • Sounds like you are possibly being hit by an odd behaviour I have noticed with MacOS X. That is, if you have a shell script wrapper, which in turn executes a Python application, and ``DYLD_LIBRARY_PATH`` is set in the environment for the shell the wrapper is run in, that environment variable, although it is seen by the shell script wrapper, is not seen by the Python program it executes. In other words, bash unsets the environment variable. – Graham Dumpleton Oct 19 '17 at 12:18
  • Do you by chance have a shell script being executed somewhere along the way from when you run the command and Python is executed? – Graham Dumpleton Oct 19 '17 at 12:19
  • 1
    The only solution of knew of was to ensure the ``DYLD_LIBRARY_PATH`` was set in the shell script wrapper. – Graham Dumpleton Oct 19 '17 at 12:21