1
//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 :-)

Johan Råde
  • 20,480
  • 21
  • 73
  • 110
Jeff Guy
  • 157
  • 1
  • 9

1 Answers1

4

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

Jim Brissom
  • 31,821
  • 4
  • 39
  • 33