Python Cython-C方法以前未在扩展类型的定义部分声明
我正在做一个项目,需要这个库(pylibol)。链接:。当我构建setup.py时,它显示了C方法“get_weight”,该方法以前没有在扩展类型“SOL”的定义部分声明过。Python Cython-C方法以前未在扩展类型的定义部分声明,python,python-2.7,cython,cythonize,Python,Python 2.7,Cython,Cythonize,我正在做一个项目,需要这个库(pylibol)。链接:。当我构建setup.py时,它显示了C方法“get_weight”,该方法以前没有在扩展类型“SOL”的定义部分声明过。 > Error compiling Cython file: > ------------------------------------------------------------ ... > dict: mapping of string to string >
> Error compiling Cython file:
> ------------------------------------------------------------ ...
> dict: mapping of string to string
> """
> params = dict()
> sol_GetModelParameters(self._c_model, get_parameter, <void*>params)
> return params
> cpdef np.ndarray[float, ndim=1, mode="c"] get_weight(self, cls_id=0):
> ^
> ------------------------------------------------------------
>
> python/pysol.pyx:141:10: C method 'get_weight' not previously declared
> in definition part of extension type 'SOL'
但事实是:
AttributeError:'PyObjectType'对象没有属性“异常检查”
知道为什么会这样吗?
我正在ubuntu上工作,正在使用python 2.7。最简单的方法可能是回到Cython的2017版本。它最初是与Cython 0.25.2一起构建的
如果不想这样做,则需要查看正在添加的行:
cdef get_weight
表示该类有一个名为get\u weight
的属性,该属性的类型为Python对象(默认情况下)。相反,您希望匹配get\u weight
cpdef np.ndarray[float, ndim=1, mode="c"] get_weight(self, cls_id=0)
(我记不清如何处理我头顶上的默认参数-您可能需要从.pyx文件中删除=0
)
或者,您可以将“.pyx”文件中的
cpdef
更改为def
。def
函数不需要事先声明(我认为cpdef
函数通常是错误的选择)。更改为Cython 0.25.2并将cdef get_weight更改为cpdef get_weight不起作用。对于最后一个解决方案,你的意思是这样吗?def np.ndarray[float,ndim=1,mode=“c”]get_weight(self,cls_id=0):但它仍然是raise错误。对于最后一个解决方案,只需执行def get_weight(self,cls_id=0)
。不要指定输出类型。如果您更改回Cython 0.25.2,那么您应该将所有内容恢复到原来的状态。不过,它看起来像一个未维护的损坏软件包-在您让它工作之前,可能有大量问题需要解决。将版本更改为Cython 0.25.2而不更改程序中的任何内容(使用原始程序)或使用修改后的程序def get_weight(self,cls_id=0)
引发了一个错误。两个建议都引发了错误命令“gcc”失败,退出状态为1。我尝试了sudo apt-get-install-python-dev
,但仍然出错。是因为我的g++版本吗?但我已经完成了前提条件(我的g++=10.2.0)。有什么想法吗?很抱歉,这有点离题,但我非常需要这个库的工作,因为遗憾的是,我没有其他的库可以使用。在它之前会有一条更有用的消息告诉你它失败的原因。我怀疑你的GCC版本是个问题。不过,您正在取得进展—您在构建它方面取得了进一步的进展。我看到的唯一错误是:src/sol/model/model.cc:9:include/sol/model/model.h:87:25:error:extra-qualification'sol::model::model::'on member'Get'[-fppermissive]87 | math::Vector*model::Get()常数代码>这意味着什么?除此之外还有很多警告。警告算作线索吗?
cdef get_weight
cpdef np.ndarray[float, ndim=1, mode="c"] get_weight(self, cls_id=0)