|
Boost Users : |
Subject: [Boost-users] [Python] can't import boost modules in an embedded interpreter
From: George Slavov (gslavov_at_[hidden])
Date: 2009-02-19 11:21:54
I am trying to create an executable which will start a python interpreter, import a module written in python, called entry.py, run its run() method and then quit. I have this part done, although I use only the C API. Now I define a boost python module like so
struct World
{
void set(std::string msg) { this->msg = msg; }
std::string greet() { return msg; }
std::string msg;
};
BOOST_PYTHON_MODULE(hello)
{
class_<World>("World")
.def("greet", &World::greet)
.def("set", &World::set)
;
}
In my entry.py I have the simple code
import hello
def run():
planet = hello.World()
planet.set("howdy")
print planet.greet()
When I run my executable, it tells me that World is undefined in the entry module. However, if in C++ I use code like this
PyRun_SimpleString("import hello");
PyRun_SimpleString("planet = hello.World()");
PyRun_SimpleString("planet.set('howdy')");
PyRun_SimpleString("print planet.greet()");
It works!
What am I doing wrong? I am attaching my (very short) code. Be advised that I am using the funky platform of Windows XP, cygwin and GCC 3.4, boost 1.33.1. That might be the problem, but I have no other platform to try this on easily.
What am I missing here?
Best,
George
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net