【发布时间】:2021-09-08 16:36:12
【问题描述】:
我的 C++ 类设置如下:
#include <boost/python.hpp>
#include "Python.h"
namespace something
{
namespace other
{
BOOST_PYTHON_MODULE(classname)
{
method_call_in_other_file();
}
方法调用在另一个文件中:
namespace something
{
namespace other
{
namespace python = boost::python;
void method_call_in_other_file()
{
//doing stuff
}
Makefile如下:
X86CPPTARGETSOL += libSOMETHING.cpp.so
libSOMETHING.cpp.so,SRCS = \
CPP_FILE_ONE.cpp \
CPP_FILE_TWO.cpp
libSOMETHING.cpp.so,DEPSOL = \
libpython2.7 \
libboost_python \
libOTHER_DEPENDENCIES
该库已正确构建在我的 lib/libSOMETHING.cpp.so 文件夹中。
我从 lib 文件夹所在的同一目录启动 python,然后将 lib/ 附加到路径:
sys.path.append('./lib')
现在,当我尝试导入我的 boost_python_module 时(如此处的快速入门所示:https://www.boost.org/doc/libs/1_68_0/libs/python/doc/html/tutorial/index.html#tutorial.quickstart)
找不到模块:
>>> import classname
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named classname
我也试过直接导入lib文件:
>>> import libSOMETHING
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named libSOMETHING
>>> import libSOMETHING.cpp
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named libSOMETHING.cpp
>>> import libSOMETHING.cpp.so
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named libSOMETHING.cpp.so
使用help('modules') 列出可用模块也不会显示任何类似于此必需导入的内容。
我在这里错过了什么?
【问题讨论】: