Компиляция Python-функций с помощью numpy lib с использованием Cython - PullRequest
1 голос
/ 09 марта 2019

У меня есть функция python, использующая модуль numpy.Например,

import numpy as np

cdef public void test():
    x = np.linspace(-4, 4, shapness)

И у меня есть main.c функция, вызывающая test function.

#include <Python.h>
#include "test.h"

int main (int argc, char **argv)
{
    printf ("Initializing Python Runtime...\n");
    Py_Initialize ();
    inittest();

    test();

    printf ("Cleanup...\n");
    Py_Finalize ();
    return 0;
}

Я собираю все с cython

cython test.pyx -o test.c
gcc -o app main.c test.c `python-config --includes --ldflags`

Когда я запускаю exe-файл, у меня появляется ошибка

Exception NameError: "name 'np' is not defined" in 'test.test' ignored

Как я могу скомпилировать все с помощью numpy lib.

...