0

I am creating an User defined module an .so file and importing that in the python module.

The functions in the library are not responding as expected.

What are the environment variables to be set to include all the library paths and headers?

Where exactly the .so file to be present ( I am placing in /usr/lib/python2.7/dist-packages)?

Is there any other settings need to done for referring the library paths and headers?

1 Answer 1

1

If you already put your .so file in /usr/lib/python2.7/dist-packages, try to make a new python file (in the same dir) named as 'my_lib.py'.

Put the below code in it:

def __bootstrap__():
   global __bootstrap__, __loader__, __file__
   import sys, pkg_resources, imp
   __file__ = pkg_resources.resource_filename(__name__,'hello_world.so')
   __loader__ = None; del __bootstrap__, __loader__
   imp.load_dynamic(__name__,__file__)
__bootstrap__()

You may need to install python-pkg-resources:

sudo apt-get install python-pkg-resources

Now you can import this my_lib as:

>>> import my_lib

EDIT: To properly manage several extensions, I would recommend to package them using distutils and then install them using just

./setup.py build
sudo ./setup.py install

Source

10
  • is there any other setting need to done? Where should I place my third party libraries and how Python will look into it?
    – Bharathi
    Apr 2, 2014 at 12:05
  • Yo mean other .so or additional .py files? Apr 2, 2014 at 12:06
  • additional .so files and header files
    – Bharathi
    Apr 2, 2014 at 12:09
  • To properly manage several extensions, I would recommend to package them using distutils and then install them using just sudo ./setup.py build install Apr 2, 2014 at 12:15
  • Can you give me an example please
    – Bharathi
    Apr 2, 2014 at 12:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .