Michael Dorner
Michael Dorner

Reputation: 20155

Importing a shared object as a module fails

I want to create a package with the following structure:

file.py
package_name/
package_name/__init__.py
package_name/module_a.py
package_name/module_b.so

module_a uses module_b and works well. But if I try to load the package package_name or the containing module module_a from file.py, an error occurs, that no module_b can be found.

What am I doing wrong?

Upvotes: 1

Views: 401

Answers (1)

Klaus D.
Klaus D.

Reputation: 14369

Your LD_LIBRARY_PATH contains . which is the current working directory. If you call module_a directly, it's the directory it is in, if you call file.py it's file.py's directory and the library can not be found there. You have several options to changes that.

  • Change your LD_LIBRARY_PATH in the environment. That can be done in your .bashrc, in a shell scrip calling your python files, by prefixing the call with LD_LIBRARY_PATH=/your/path or by modifying os.environ in Python.
  • you can also symlink the library to the other folder.
  • you can install the library to a system-wide library folder.

Upvotes: 2

Related Questions