Skip to content

Instantly share code, notes, and snippets.

@vfdev-5
Last active March 1, 2017 12:34
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save vfdev-5/7d958b381e3795d96e9b0a6d7609f17b to your computer and use it in GitHub Desktop.
(macosx) @rpath problem with otbApplication.py - OTB-5.8.0

Problem when importing otbApplication under MacOSX El Capitain.

>>> import otbApplication

----> 1 import otbApplication
      2 
      3 from image_utils import get_filename

~/Documents/OTB-5.8.0-Darwin64/lib/python/otbApplication.py in <module>()
     26                 fp.close()
     27             return _mod
---> 28     _otbApplication = swig_import_helper()
     29     del swig_import_helper
     30 else:

~/Documents/OTB-5.8.0-Darwin64/lib/python/otbApplication.py in swig_import_helper()
     22         if fp is not None:
     23             try:
---> 24                 _mod = imp.load_module('_otbApplication', fp, pathname, description)
     25             finally:
     26                 fp.close()

ImportError: dlopen(~/Documents/OTB-5.8.0-Darwin64/lib/python/_otbApplication.so, 2): Library not loaded: @rpath/libOTBApplicationEngine-5.8.1.dylib
  Referenced from: ~/Documents/OTB-5.8.0-Darwin64/lib/python/_otbApplication.so
  Reason: image not found

Checking the dependencies, we see

otool -L _otbApplication.so 
_otbApplication.so:
	/System/Library/Frameworks/Python.framework/Versions/2.7/Python (compatibility version 2.7.0, current version 2.7.6)
	@rpath/libOTBApplicationEngine-5.8.1.dylib (compatibility version 1.0.0, current version 1.0.0)
	@rpath/libOTBImageIO-5.8.1.dylib (compatibility version 1.0.0, current version 1.0.0)
	@rpath/libOTBIORAD-5.8.1.dylib (compatibility version 1.0.0, current version 1.0.0)
  ...

A solution to the problem is to use install_name_tool

install_name_tool -change @rpath/libOTBApplicationEngine-5.8.1.dylib path/to/OTB/lib/libOTBApplicationEngine-5.8.1.dylib _otbApplication.so 

and in a batch mode :

cd /path/to/OTB-5.8.0

otool -L lib/python/_otbApplication.so | grep -ohe "@rpath/\(\S\)*" | grep -ohe "lib\(\S\)*" | while read i; do install_name_tool -change @rpath/$i $PWD/lib/$i lib/python/_otbApplication.so; done

Bonus If you use python from brew and not a system one, you will need to change

/System/Library/Frameworks/Python.framework/Versions/2.7/Python

by the following command:

install_name_tool -change /System/Library/Frameworks/Python.framework/Versions/2.7/Python /usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/Python _otbApplication.so
@gpo-geo
Copy link

gpo-geo commented Mar 1, 2017

Thanks for this fix !
Would it work if you replace @rpath/ with @rpath/../ in _otbApplication.so dependencies ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment