Search code examples
pythonnumpycoredumppython-c-api

Python C-API and Numpy: core dump on import_array


//testNumpy.c
#include<Python.h>
#include<numpy/arrayobject.h>
#include<stdio.h>
int main(){
    printf("import_array\n");fflush(stdout);
    import_array();
    printf("import_array done\n");fflush(stdout);
}

$ gcc -I/usr/include/python2.6 -lpython2.6 testNumpy.c&&./a.out
import_array
Segmentation fault (core dumped)

What could I possibly be doing wrong on such a simple program? I'm tearing my hair out :-)


Solution

  • For starters, you did not initialize Python properly. Call Py_Initialize() before trying to initialize NumPy.