0

I wrote a Python 3 extension module in C but cannot seem to get Python to import it.

Is there any way to let Python print out which shared libraries (.so on Linux) it tries to load and why it fails?

Sadly all the docs I read don't really help since none describes the native import procedure in a concise way.

What I tried is:

ctypes.CDLL("libmydep1.so")
ctypes.CDLL("libmydep2.so")

try:
    import my_main
    print("Load python")
except:
    ctypes.CDLL("libmylib.so")
    print("Load shared object")

Which always prints Load shared object.

libmylib.so contains the python entry point but loading it as Python 3 extension does not seem to work, although loading as a shared library does.

EDIT:

Python does not honor linux conventions. So for a lib you do not name it libmylib.so but mylib.so.

Even worse, it only loads my_main, when the so is named my_main.so. So annoying.

abergmeier
  • 13,224
  • 13
  • 64
  • 120

1 Answers1

0

Try to look at /proc/<pid>/maps directory.

Or try to use lsof -p <PID> command in shell.

Source of answer is this forum. lsof man page. See also this answer.

Community
  • 1
  • 1
nio
  • 5,141
  • 2
  • 24
  • 35
  • This is just helpful so that I know that it does not load my .so at all. Still I lack the basic tools to see what python is trying to load and why and why it fails. – abergmeier Jul 27 '13 at 14:03