4

I have made a .so module with boost.python and can import it from local folder.

|--my_class.so
|--python_code.py

in python_code.py

from my_class import *

Obviously if I put python_code.py in a different folder, from my_class import * would fail.

I am wondering if there is a way that I can "install" my_class.so in a gobal package location that I can import it from any python script. So my_class has the same status as packages like numpy .

1 Answer 1

1

You should be able to move the .so file somewhere on your python library path. On my machine one example is the directory /usr/lib/python2.7

One way you might consider doing this is with a setup.py file, which can be configured to handle your build and install.

In the past I've sometimes just copied it there by hand for testing or put a something such as below into a Makefile so it copies after compile:

#
#   Install the python module
#
install: /usr/local/lib/python2.7/dist-packages/MyModule.so

/usr/local/lib/python2.7/dist-packages/MyModule.so: python-module
    cp $(BIN)MyModule.so /usr/local/lib/python2.7/dist-packages/MyModule.so
Sign up to request clarification or add additional context in comments.

2 Comments

I found this link, I think I have to add it manually. Does it load automatically for you?
Yeah, if the module is in the pythonpath it will load. Check the version of python you are using and add the .so file to one of the directories such as /usr/lib/python2.7/dist-packages/*.so

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.