1

I am using python(2.6.4)-swig(1.3.4) , to access some c++ code that has been compiled into a .so. swig generates some python code that imports the .so with the help of the imp module.

The find_module succeeds and gets the correct path. But the import_module throws up an ImportError.

File "/a/vin31f2/vol/vin31f2v11/cs_ets_03/pradyotd/shadows/testframework/src/MessageRouter/src/swig/MessageFactory.py", line 24, in swig_import_helper
_mod = imp.load_module('_MessageFactory', fp, pathname, description)
ImportError: /a/vin31f2/vol/vin31f2v11/cs_ets_03/pradyotd/shadows/testframework/src/MessageRouter/src/swig/_MessageFactory.so: cannot open shared object file: No such file or directory all 

Please note that the file is infact there /a/vin31f2/vol/vin31f2v11/cs_ets_03/pradyotd/shadows/testframework/src/MessageRouter/src/swig/_MessageFactory.so.

Any suggestions as to how I can solve this?

Also , the same thing seems to run in python 2.6.5 on a different machine

Pradyot
  • 2,897
  • 7
  • 41
  • 58
  • IIRC Python says "No such file or directory" for a library where the its dependencies can't be resolved. Use `ldd` to check they can all be resolved from where you're trying to load it and use `LD_LIBRARY_PATH` to add things to the library path if needed. – Flexo Aug 28 '12 at 16:29
  • Looking at the help for the imp, module it seems there are other methods load_compiled,load_dynamic,load_package, in addition to load_module. – Pradyot Aug 28 '12 at 16:29
  • I actually tried adding my path to the LD_LIBRARY_PATH, that did'nt seem to do it, (and on the machine, where this is not an issue, LD_LIBRARY_PAH was blank) – Pradyot Aug 28 '12 at 16:30
  • 1
    Ok, but that doesn't confirm that the linker can resolve all of the depndencies - what does `ldd /a/vin31f2/vol/vin31f2v11/cs_ets_03/pradyotd/shadows/testframework/src/MessageRouter/src/swig/_MessageFactory.so` show? I'd bet it shows not found for at least one. (Basically the same as [Cross compiling Gnu Radio for Openwrt](http://stackoverflow.com/q/11659973) I suspect) – Flexo Aug 28 '12 at 16:32
  • so on one machine (where it does work, it lists the various libraries linked in). On the problem machine I get the message "not a dynamic executable. And the load_dynamic was a dead end. – Pradyot Aug 28 '12 at 16:39
  • 1
    That would explain the problem you're seeing then - you need to compile and link it correctly for the specific platform you want to run it on. – Flexo Aug 28 '12 at 16:41

0 Answers0