pythonmacosshared-librariesdylibhoudini

Python module cannot load shared library, Reason: image not found


I'm trying to use the Houdini Python module that ships with the application and is part of Houdini's installation folder, outside the standard Python paths. After following the installation instructions, running the Houdini Terminal 16.5.571 script and adding /Applications/Houdini/Houdini16.5.571/Frameworks/Houdini.framework/Versions/Current/Resources/houdini/python2.7libs to _virtualenv_path_extensions.pth in my site-packages folder the hou module can be imported, the Python part that is. However it fails loading the dynamic libraries.

Error message

Traceback (most recent call last):

File "myscript.py", line 7, in <module>
    import hou
  File "/Applications/Houdini/Houdini16.5.571/Frameworks/Houdini.framework/Versions/Current/Resources/houdini/python2.7libs/hou.py", line 19, in <module>
    import _hou
ImportError: dlopen(/Applications/Houdini/Houdini16.5.571/Frameworks/Houdini.framework/Versions/Current/Resources/houdini/python2.7libs/_hou.so, 2): Library not loaded: @rpath/Houdini.framework/Versions/16.5.571/Houdini
  Referenced from: /Applications/Houdini/Houdini16.5.571/Frameworks/Houdini.framework/Versions/Current/Resources/houdini/python2.7libs/_hou.so
  Reason: image not found

All files and folders mentioned in the error message are located within the Houdini path /Applications/Houdini/Houdini16.5.571/Frameworks/Houdini.framework/Versions/Current with Current being a symlink to 16.5.571.

Python module

Resources/houdini/python2.7libs/hou.py

The Python module is found.

Shared libraries

Resources/houdini/python2.7libs/_hou.so`

This contains a a reference to @rpath/Houdini.framework/Versions/16.5.571/Houdini which it is presumably trying to look up.

Houdini

This seems to link to the actual dylib files, containing @loader_path/Libraries and dylib...@rpath/libHoudiniUI etc. and many others.

I read here Cannot find dynamic library when running a Python script from Bazel that SIP may be causing it but even after ln -s the shared libraries into /usr/local/lib the error still occured.

I am using pyenv but tried with the system Python environment, resulting in the same behaviour.

Any suggestions?


Solution

  • The answer in dyld: Library not loaded ... Reason: Image not loaded pointed me into the right direction, suggesting to rewrite the dynamic library paths using otool.

    Listing all libraries loaded by _hou.so, shows the following list, with @rpath/Houdini.framework/Versions/16.5.571/Houdini being the one that causes the issue.

    otool -L /Applications/Houdini/Houdini16.5.571/Frameworks/Houdini.framework/Versions/Current/Resources/houdini/python2.7libs/_hou.so
    /Applications/Houdini/Houdini16.5.571/Frameworks/Houdini.framework/Versions/Current/Resources/houdini/python2.7libs/_hou.so:
        @rpath/Houdini.framework/Versions/16.5.571/Houdini (compatibility version 1.0.0, current version 16.5.255)
        /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 1443.14.0)
        /System/Library/Frameworks/IOKit.framework/Versions/A/IOKit (compatibility version 1.0.0, current version 275.0.0)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.0.0)
        /System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 22.0.0)
        /System/Library/Frameworks/QTKit.framework/Versions/A/QTKit (compatibility version 1.0.0, current version 1.0.0)
        /System/Library/Frameworks/OpenCL.framework/Versions/A/OpenCL (compatibility version 1.0.0, current version 1.0.0)
        /System/Library/Frameworks/AudioToolbox.framework/Versions/A/AudioToolbox (compatibility version 1.0.0, current version 492.0.0)
        /System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL (compatibility version 1.0.0, current version 1.0.0)
        /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 400.9.0)
    

    Rewriting the path can be done using install_name_tool -change.

    install_name_tool -change @rpath/Houdini.framework/Versions/16.5.571/Houdini /Applications/Houdini/Houdini16.5.571/Frameworks/Houdini.framework/Versions/16.5.571/Houdini /Applications/Houdini/Houdini16.5.571/Frameworks/Houdini.framework/Versions/Current/Resources/houdini/python2.7libs/_hou.so
    

    It may be better to use a relative path.