Boost Python 示例失败两次
我是唯一一个尝试使用以下组合的人吗: boost_1_45_0、MSVC 10、Python31?
我发现 boost (boost_1_45_0\libs\python\example\quickstart\embedding.cpp) 中的基本示例既没有编译(我找到了如何修复它,请参见下文)也没有工作。 编译时问题:
if (PyImport_AppendInittab("embedded_hello", initembedded_hello) == -1)
throw std::runtime_error("Failed to add embedded_hello to the interpreter's "
"builtin modules");
我发现正确的名称不是 initembedded_hello 而是 init_module_embedded_hello。所以我的第一个问题是我对这个重命名是正确的吗?
第二个问题是导入我声明的模块时出现 SystemError: NULL result without error in PyObject_Call:
from embedded_hello import *
注释掉导入显示内部 python 模块(如 io)工作正常。那么第二个问题导入有什么问题?
任何帮助将不胜感激!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于 Python 3,使用 PyInit_embedded_hello 而不是 initembedded_hello。适用于我的 msvc9。
显然,quickstart\embedding.cpp 还没有针对 Python 3 进行更新。看看 pyhon/test/exec.cpp,它是相似的并且是最新的。
Msvc10 使用与 Python 不同的 C 运行时库,这可能会导致运行时崩溃。用于构建 Python 2.6、2.7、3.1 和 3.2 扩展的推荐编译器是 msvc9,或链接到 vc90crt 的编译器。
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.