python - 导入 swig 生成的模块时,Python 提示缺少删除方法

标签 python c++ swig

我们有一组由 swig 包装的用于 python 的 C++ 类。在 python 中导入这些类之一时,我们收到以下错误消息:

File ".../myobjects.py", line 176, in <module>
class RT(_object):
File ".../myobjects.py", line 187, in RT
\__swig_destroy__ = _myobjects.delete_RT
AttributeError: 'module' object has no attribute 'delete_RT'

myobjects.py swig 生成的 RT 代码如下所示:

class RT(_object):
    __swig_setmethods__ = {}
    __setattr__ = lambda self, name, value: _swig_setattr(self, RT, name, value)
    __swig_getmethods__ = {}
    __getattr__ = lambda self, name: _swig_getattr(self, RT, name)
    __repr__ = _swig_repr
    def __init__(self, *args):
        this = _myobjects.new_RT(*args)
        try: self.this.append(this)
        except: self.this = this
    def getName(self): return _myobjects.RT_getName(self)
    __swig_destroy__ = _myobjects.delete_RT
    __del__ = lambda self : None;

创建 _myobjects.so 的 cxx 文件具有以下行:

SWIGINTERN PyObject *_wrap_delete_RT(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
  PyObject *resultobj = 0;
  RT *arg1 = (RT *) 0 ;
...

简而言之,一切都按顺序出现,但我们仍然遇到 python 错误。

有什么想法吗?

谢谢,

汤姆

最佳答案

嗯,不知道为什么会这样,但是 cxx 文件中这个类之前的类被两个 i 文件包含了。删除一个夹杂物解决了这个问题。

关于python - 导入 swig 生成的模块时,Python 提示缺少删除方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30593519/

相关文章:

c++ - 在 Windows 中为 python 编译 SWIG 包装器

c++ - 使用 cmake 和其他库 Swig

python - 在 appengine 中对 collection_name 进行排序

python - 在 python 中排序元组列表

c++ - 在 C++ 中使用映射器处理派生类创建

c++ - 尝试创建私有(private)成员数组,其大小从 C++ 中的初始化列表给出(<vector> 使用被禁止)

c++ - Ubuntu 中的 execl() 参数

java - 自定义 swig 生成的代码

python - 在执行下面的代码时,我得到了这个 'TypeError: img is not a numerical tuple'

python - 如何隐藏工具栏中的元素? wxpython