C++开发python扩展模块:ImportError: dynamic module does not define init function (initRabbit)解决办法
2012-02-20 13:44
706 查看
原文首发地址:http://www.atolin.net/c%E5%BC%80%E5%8F%91python%E6%89%A9%E5%B1%95%E6%A8%A1%E5%9D%97%EF%BC%9Aimporterror-dynamic-module-does-not-define-init-function-initrabbit%E8%A7%A3%E5%86%B3%E5%8A%9E%E6%B3%95/
ImportError: dynamic module does notdefine init function (initRabbit)
经过分析,原因是,没有正确导出封装python扩展模块所必需的init函数,正确的导出方法为:
#ifdef PYRABBIT_EXPORTS
#define PYRABBIT_API __declspec(dllexport)
#else
#define PYRABBIT __declspec(dllimport)
#endif
extern "C" PYRABBIT_APIvoid initRabbit(){
PyObject* m=Py_InitModule("Rabbit",RabbitMethods);
}
上面的initRabbit()函数的声明定义,是关键。是不是豁然开朗迎刃而解呢。
用C++为Python编写扩展模块(动态链接库),并在Python中调用C++开发的扩展功能函数过程,遇到如下错误的童鞋,系不系很苦恼啊:
ImportError: dynamic module does notdefine init function (initRabbit)经过分析,原因是,没有正确导出封装python扩展模块所必需的init函数,正确的导出方法为:
#ifdef PYRABBIT_EXPORTS
#define PYRABBIT_API __declspec(dllexport)
#else
#define PYRABBIT __declspec(dllimport)
#endif
extern "C" PYRABBIT_APIvoid initRabbit(){
PyObject* m=Py_InitModule("Rabbit",RabbitMethods);
}
上面的initRabbit()函数的声明定义,是关键。是不是豁然开朗迎刃而解呢。
相关文章推荐
- pvanet的问题--ImportError: dynamic module does not define init function (initcython_bbox)
- 编译caffe的Python借口,提示:ImportError: dynamic module does not define module export function (PyInit__caffe)
- ImportError: dynamic module does not define module export function (PyInit_cv_bridge_boost)
- c++开发python扩展模块:cannot open file ‘python25_d.lib’解决办法
- Python 3中套接字编程中遇到TypeError: 'str' does not support the buffer interface的解决办法
- Python 3中套接字编程中遇到TypeError: 'str' does not support the buffer interface的解决办法
- PHP扩展开发报错解决[error: ‘PHP_FE_END’ undeclared here (not in a function)]
- c++ error 2064: term does not evaluate to a function taking 1 arguments解决方法
- 全网最详细的跑python2.7时出现from mysql import connector ImportError: No module named mysql的问题解决办法(图文详解)
- Python 3.6 模块安装“error: Microsoft Visual C++ 14.0 is required...”时出错的解决办法
- caffe配置问题:dynamic module does not define module export function(PyInit_caffe)
- 使用vue时Module build failed: TypeError: this._init is not a function错误的解决方法
- Python 的PIL,可以解决ImportError The _imagingft C module is not installed
- python错误:ImportError: No module named setuptools解决办法
- PHP扩展开发报错解决[error: ‘PHP_FE_END’ undeclared here (not in a function)] .
- Python 3中套接字编程中遇到TypeError: 'str' does not support the buffer interface的解决办法
- PHP扩展开发报错解决[error: ‘PHP_FE_END’ undeclared here (not in a function)] .
- C++封装python扩展模块ImportError: No module named 原因分析
- Python 3中套接字编程中遇到TypeError: 'str' does not support the buffer interface的解决办法
- Python 3中套接字编程中遇到TypeError: 'str' does not support the buffer interface的解决办法