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 .

vikingshore
  • 165
  • 1
  • 2
  • 6

1 Answers1

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
joeButler
  • 1,643
  • 1
  • 20
  • 41
  • I found [this link](http://stackoverflow.com/questions/19876079/opencv-cannot-find-module-cv2), I think I have to add it manually. Does it load automatically for you? – vikingshore Apr 13 '15 at 23:12
  • 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 – joeButler Apr 14 '15 at 08:21