0

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!

RoboCop87
  • 825
  • 1
  • 8
  • 21

1 Answers1

0

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.

Amias
  • 335
  • 6
  • 16
  • Im using a custom build of linux, and it doesn't come pre-installed with bz2 and there is no package manager to help get it. I cross compiled it from source. – RoboCop87 Jun 13 '16 at 15:20
  • As far as importing a python module which uses it, I tried writing a python module that imports the dl module and using dl.open('bz2.so') but that did not work either. – RoboCop87 Jun 13 '16 at 15:21