'Python dynamic imports of .so files throws several errors

I have recursively copied a MacOS (11.6.1) app directory into another folder, and inside Contents/Frameworks I have a .dylib file I would like to import into Python for analysis of methods. (I wrote a script to copy all the .dylib files to .so so that they could be imported.)

When I try to load a module, either through the ctypes interface or just regular import syntax, I get an error:

from Contents.Frameworks import librocs_core
Traceback (most recent call last):
  File "/Users/a2435191/Desktop/programming/get-propietary-soundfiles/main.py", line 1, in <module>
    from Contents.Frameworks import librocs_core
ImportError: dlopen(/Users/a2435191/Desktop/programming/get-propietary-soundfiles/Contents/Frameworks/librocs_core.so, 2): Library not loaded: @executable_path/../Frameworks/libkit.dylib
  Referenced from: /Users/a2435191/Desktop/programming/get-propietary-soundfiles/Contents/Frameworks/librocs_core.so
  Reason: image not found

However, libkit.dylib (as well as libkit.so) definitely exists in Contents/Frameworks!

When I load libkit I get an error as well:

ImportError: dynamic module does not define module export function (PyInit_libkit)

I'm not sure how to proceed— do I need to modify the dependencies using otool and install_name_tool? Is it because I copied from the app directory into a new project folder? What is @executable_path (as in how do I find the absolute path)?

Thanks in advance.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source