Cython: C语言封装Python库出错

import erfa

>>> erfa.zp()

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

  File "~/app/local/anaconda3/envs/python3.8/lib/python3.8/site-packages/erfa/core.py", line 19387, in zp

    p = ufunc.zp()

ValueError: At least one iterator operand must be non-NULL

>>>

 

erfa是一个C语言封装成的Python库。问题出在封装上了

pyerfa库网址:https://github.com/liberfa/pyerfa

对应的C语言源码:https://github.com/liberfa/erfa/tree/74ca988069f77187b7bd21e2432792f877cc371e

 

 

 

 

// file: erfa.cpp
#include "erfa.h"

void eraZp(double p[3])
/*
**  - - - - - -
**   e r a Z p
**  - - - - - -
**
**  Zero a p-vector.
**
**  Returned:
**     p        double[3]      zero p-vector
**
**  This revision:  2020 August 25
**
**  Copyright (C) 2013-2021, NumFOCUS Foundation.
**  Derived, with permission, from the SOFA library.  See notes at end of file.
*/
{
   p[0] = 0.0;
   p[1] = 0.0;
   p[2] = 0.0;

   return;

}

 

### 封装后的 core.py 文件 片段
def zp():
    """
    Zero a p-vector.

    Parameters
    ----------

    Returns
    -------
    p : double array

    Notes
    -----
    Wraps ERFA function ``eraZp``. The ERFA documentation is::

        - - - - - -
         e r a Z p
        - - - - - -

        Zero a p-vector.

        Returned:
           p        double[3]      zero p-vector

        This revision:  2020 August 25

        Copyright (C) 2013-2021, NumFOCUS Foundation.
        Derived, with permission, from the SOFA library.  See notes at end of file.

    """
   p = ufunc.zp()
   return p

 

line 19387

题主试一试运行时将.cpp文件放在与安装位置同一路径下

iterator循环里面的对象是空值,请检查一下

你这个erfa和python的版本是不是不适配,建议降低或升级版本试一下

您好,我是有问必答小助手,你的问题已经有小伙伴为您解答了问题,您看下是否解决了您的问题,可以追评进行沟通哦~

如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~

ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632

erfa.zp()

这个用法是错误的。因为必须要有一个参数。不能无参调用。应该这么调用

double_list = [0.1, 0.2, 0.5]

erfa.zp(double_list)

print(double_list)