Trouble importing shared object in Python
Question: I am attempting to import a shared object into my python code, like so:

    
    
    import bz2
    

to which I get the following error:

> ImportError: ./bz2.so: cannot open shared object file: No such file or
> directory

Using the imp module, I can verify that Python can actually find it:

    
    
    >>> import imp
    >>> imp.find_module('bz2')
    (<open file 'bz2.so', mode 'rb' at 0xb6f085f8>, 'bz2.so', ('.so', 'rb', 3))
    

The shared object file is in my PYTHONPATH and my LD_LIBRARY_PATH.

Any insights into why I can't import this shared object? Thanks!


Answer: bz2.so is the shared object the provides the bzip functionality (which was
written in C) for the python modules. You don't import it directly when you do
import bz2 , you are actually importing a python module called bz2 which then
uses the .so file.

This usually means you haven't got the development version of the bzip library
installed or you don't have a c compiler setup for the pip installer to use to
build this for you.

You don't say which linux you are using but the general pattern is look in the
package manager for bzip2 dev or devel packages and install those.

