【发布时间】:2021-11-22 02:28:54
【问题描述】:
我正在关注C Python extension tutorial 来创建新类型。
我创建了文件custom.c、setup.py 并将以下行添加到我的CMakeLists.txt:
execute_process(WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} COMMAND ${PYTHON_BIN} setup.py build)
但是当我跑步时
Py_Initialize();
PyImport_AddModule("custom"));
PyRun_SimpleString("import custom\nmycustom = custom.Custom()");
PyErr_Print();
即使我将生成的.pyd 的路径添加到sys.path,我也得到了Attribute error: module 'custom' has no attribute 'Custom'
模块的 Python 帮助是
Help on module custom:
NAME
custom
FILE
(built-in)
我正在使用 Python 3.8 在 Windows 10 上运行
但我可以直接从 Python 终端导入和使用模块
【问题讨论】:
-
或许this可以帮到你
-
不,它没有:/ 仍然出现属性错误
-
这不是很完整...(请参阅minimal reproducible example)您必须按照该外部链接中的说明重新创建错误。
-
也许检查你构建程序的“当前文件夹”是否恰好有一个名为
custom.py的文件,或者你没有一个名为custom的包?跨度>
标签: python c++ python-c-api