3

I'm building a C++ python module on MacOS.

On my machine I have python, installed in directory /Library/Frameworks/Python.framework/Versions/3.9. I'm specifing python includes directory as -I/Library/Frameworks/Python.framework/Versions/3.9/Headers and libraries directory as -L/Library/Frameworks/Python.framework/Versions/3.9/lib -lpython3.9.

So it builds good and runs good on my machine and other machines, where python is installed into /Library/Frameworks/Python.framework/Versions/3.9.

But when I move my library to machine, where python is installed into another folder, like /usr/local/Cellar/python@3.9/3.9.12/Frameworks/Python.framework/Versions/3.9, I'm getting import module error.

otool -L _mymodule.so command returns hardcoded absolute path to /Library/Frameworks/Python.framework/Versions/3.9. I know, that I can change the path using install_name_tool, but I don't want to ask and explain my module users to do that, as well as to make a symlink.

How can I make module more portable and python install path independent?

David
  • 39
  • 2
  • The only suitable for me way I've found is to add some common paths during building the library using install_name_tool: install_name_tool -add_rpath /Users/runner/hostedtoolcache/Python/3.10.2/x64/lib ./bin/release/darwin/x64/_mylib.so install_name_tool -add_rpath /usr/local/opt/python@3.10.2/Frameworks/Python.framework/Versions/${{ matrix.py }}/lib ./bin/release/darwin/x64/_mylib.so install_name_tool -add_rpath /Library/Frameworks/Python.framework/Versions/3.10.2/lib ./bin/release/darwin/x64/_mylib.so – David Nov 22 '22 at 08:31

0 Answers0