Boost logo

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