Dewfy
Dewfy

Reputation: 23614

Boost Python example failed twice

Am I alone who tried to use following combination: boost_1_45_0, MSVC 10, Python31 ?

I have discovered that basic sample from boost (boost_1_45_0\libs\python\example\quickstart\embedding.cpp) Neither compiled (I found how to fix it see below) nor works. Compile time problem:

if (PyImport_AppendInittab("embedded_hello", initembedded_hello) == -1)
  throw std::runtime_error("Failed to add embedded_hello to the interpreter's "
             "builtin modules");

I have discovered that correct name is not initembedded_hello but init_module_embedded_hello. So my first question am I right about this renaming?

The second problem is SystemError: NULL result without error in PyObject_Call when importing my declared module:

from embedded_hello import *

Commenting out importing shows that internal python's modules (like a io) works fine. So the second question what the problem with importing?

Any help would be appreciated!

Upvotes: 2

Views: 1302

Answers (1)

cgohlke
cgohlke

Reputation: 9437

Use PyInit_embedded_hello instead of initembedded_hello for Python 3. Works for me with msvc9.

Apparently quickstart\embedding.cpp has not been updated for Python 3. Take a look at pyhon/test/exec.cpp, which is similar and up to date.

Msvc10 uses a different C runtime library than Python, which might lead to runtime crashes. The recommended compiler for building Python 2.6, 2.7, 3.1, and 3.2 extensions is msvc9, or a compiler that links against vc90crt.

Upvotes: 5

Related Questions