我试图将7个c ++类与// File : quadedge.i to hold all the interface files together
%module quadedge
%include cell.i
%include list.i
%include face.i
%include edge.i
%include obj.i
%include array.i
%include vertex.i
一起包装,并将它们放在同一个库中。以下是我的接口文件,用于保存所有类。
cell.i
每个接口文件list.i
,//file : list.i : interface file for list.hh
%module list
%{
#include "list.hh"
%}
%include list.hh
,...作为接口文件
setup.py
我使用了一个disutil文件#setup.py file:
from setuptools import setup, Extension
setup(name='quadedge',
version='0.1',
ext_modules=[Extension('_quadedge', sources=['array.cc','edge.cc','list.cc','cell.cc','face.cc','obj.cc','vertex.cc', 'quadedge.i'],
swig_opts=['-c++'],
)],
headers=['array.hh','edge.hh','list.hh','cell.hh','face.hh','obj.hh','vertex.hh',]
)
来包装这些类。
python setup.py build_ext --inplace
并正在运行
quadedge
它运行良好,几乎没有警告但是库已经创建了。然后我尝试导入>>>import quadedge as qd
>>>a = qd.vertex()
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-4-e068e492f5b5> in <module>()
----> 1 a = qd.vertex()
AttributeError: 'module' object has no attribute 'vertex'
库。
quadedge
我想我不太清楚SWIG是如何包装这些类的。我以为dir(qd)
将是主库,其他所有类都是这个库的子类。
['Cell',
'CellFaceIterator',
'CellFaceIterator_swigregister',
'CellVertexIterator',
'CellVertexIterator_swigregister',
'Cell_kill',
'Cell_make',
'Cell_makeTetrahedron',
'Cell_swigregister',
'Edge',
'Edge_kill',
'Edge_make',
'Edge_splice',
'Edge_swigregister',
'Face',
'FaceEdgeIterator',
'FaceEdgeIterator_swigregister',
'Face_kill',
'Face_make',
'Face_swigregister',
'Vertex',
'VertexEdgeIterator',
'VertexEdgeIterator_swigregister',
'Vertex_kill',
'Vertex_make',
'Vertex_swigregister',
'__builtins__',
'__doc__',
'__file__',
'__name__',
'__package__',
'_newclass',
'_object',
'_quadedge',
'_swig_getattr',
'_swig_getattr_nondynamic',
'_swig_property',
'_swig_repr',
'_swig_setattr',
'_swig_setattr_nondynamic',
'objCloneCell',
'objReadCell',
'objWriteCell']
{{1}}
答案 0 :(得分:0)
问题出在命令的情况下。我正在qd.vertex()
,因为代码区分大小写,因此它应该是qd.Vertex()
。一个真正愚蠢的错误需要花费很多时间来弄明白。