unable to load the module from simple example
Hello
I have followed the simple example from the python boost wiki page:
my source file py_moddef.cc:
___________________________________________
#include <string>
#include
import sys sys.path.append("the_path")
I am not able to import the module "hello_ext" defined in py_moddef.cc, but I am able to import each other python module from this path, so something wrong is with the shared library.
import hello_ext ImportError: No module named hello_ext
Please explain to me what is wrong. I will be gratefull for any help. Best regards Cuma
Cuma Tyszkiewicz wrote:
Hello
I have followed the simple example from the python boost wiki page:
my source file py_moddef.cc: ___________________________________________ #include <string> #include
char const* greet() { return "hello, world"; }
BOOST_PYTHON_MODULE(hello_ext) { using namespace boost::python; def("greet", greet); } ____________________________________________
In the next step I have built the shared library
1. g++ -c -fpic -I/usr/include/python2.6/ py_moddef.cc 2. ld -G py_moddef.o -o libpy_moddef.so
I recommend that you never invoke "ld" directly. That's dangerous.
The libpy_moddef.so file I have copied to the directory which next was included to PYTHONPATH
import sys sys.path.append("the_path")
I am not able to import the module "hello_ext" defined in py_moddef.cc, but I am able to import each other python module from this path, so something wrong is with the shared library.
import hello_ext ImportError: No module named hello_ext
Please explain to me what is wrong. I will be gratefull for any help.
if libpy_modedef.so uses Boost.Python, without linking to Boost.Python library, things won't work. You have to link to that library, and make sure it's found by dynamic linker. - Volodya
participants (2)
-
Cuma Tyszkiewicz
-
Vladimir Prus