使用Boost Python的Python模块是空的?
python module using boost python is empty?
我正在尝试学习提升python API来创建我自己的python(3.6(模块。 我能够成功编译以下 c++ 代码并获得生成的 pythonTest.dll 我正在生成。
#define BOOST_ALL_DYN_LINK
#include <boost/python.hpp>
#include <string>
const std::string hello_world(void)
{
return std::string("hello world!n");
}
BOOST_PYTHON_MODULE(pythonTest)
{
namespace python = boost::python;
python::def("hello_world", hello_world);
}
然后,我将 pythonTest.dll 复制到我的模块文件夹中,如下所示。 (我将pythonTest.dll重命名为pythonTest.pyd(
pythonTest
__init__.py
pythonTest.pyd
当我执行python时,它将导入模块,但它找不到我的hello_world函数:
Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 18:41:36) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pythonTest
>>> pythonTest.hello_world()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
**AttributeError: module 'pythonTest' has no attribute 'hello_world'**
>>> help(pythonTest)
Help on package pythonTest:
NAME
pythonTest
PACKAGE CONTENTS
pythonTest
FILE
<...>pythontest__init__.py
>>> dir(pythonTest)
['__builtins__', '__cached__', '__doc__', '__file__', '__loader__','__name__', '__package__', '__path__', '__spec__']
>>>
我错过了什么? 谢谢。
编辑: 这是可视化工作室构建的输出:
1>------ Rebuild All started: Project: pythonTest, Configuration: Release x64 ------
1>Build started 7/10/2017 2:49:53 PM.
1>InitializeBuildStatus:
1> Creating "x64ReleasepythonTest.tlogunsuccessfulbuild" because "AlwaysCreate" was specified.
1>ClCompile:
1> pythonTest.cpp
1>G:DataBackupdev-vc133rdPartyboost_1_64_0boost/python/detail/caller.hpp(55): warning C4244: 'return' : conversion from 'Py_ssize_t' to 'unsigned int', possible loss of data
1>Link:
1> Creating library G:DataBackupdev-vc13temppythonTestx64ReleasepythonTest.lib and object G:DataBackupdev-vc13temppythonTestx64ReleasepythonTest.exp
1> Generating code
1> Finished generating code
1> pythonTest.vcxproj -> G:DataBackupdev-vc13temppythonTestx64ReleasepythonTest.dll
1>PostBuildEvent:
1> 1 file(s) copied.
1>FinalizeBuildStatus:
1> Deleting file "x64ReleasepythonTest.tlogunsuccessfulbuild".
1> Touching "x64ReleasepythonTest.tlogpythonTest.lastbuildstate".
1>
1>Build succeeded.
1>
1>Time Elapsed 00:00:04.21
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
尝试使用 dir(( 函数
>>> dir(pythonTest)
这将向您展示可用的方法和函数 包数
相关文章:
- 在 python 模块中导入子模块时PyImport_Import失败
- C++ Python 模块在 Blender 中崩溃,但在 Python 控制台中不会崩溃
- 如何使用 swig C++命名空间作为 python 模块公开
- 如何将 cv::mat 对象从 python 模块传递到 c++ 函数并返回返回的 cv::mat 类型为对象?
- C++ Swig Python 模块中的内存泄漏
- boost.python模块扩展生成SIGSEGV
- 使用Boost Python的Python模块是空的?
- 为什么无法在 Cocoa 应用程序调用的 C++ func 中嵌入自定义 Python 模块
- 来自C 的自动化Python模块的张量源
- 如何使用C++导入多个同名的 python 模块
- C++ Python 模块导入错误: "undefined symbol: Py_InitModule3" ( Py_InitModule () )
- 使用 Boost.Python 创建的 Python 模块不会被导入
- 导入 Boost Python 模块 (function_impl_base9max_arityEv) 时出错
- numpy.core.multiarray在通过Xcode中开发的C 应用程序调用Python模块时未能导入
- 运行时错误:找不到与 ImageSensor 匹配的 Python 模块
- GDB Python模块读取内存内容
- 我可以编译boost.python模块而没有BJAM
- C++优化级别是否会影响Swig Python模块的性能
- 如何从python模块(boost.python)导入类
- 使用C/neneneba API和C++类编写Python模块