1

I'm trying to compile the following c++ file

#include <iostream> 
#include <Python.h>
#include <numpy/npy_math.h>
 
using namespace std; 
int main() 
{ 
 
   cout << "Hello World" << endl;    // prints value of i 
}

with the following

clang++ main.cpp -std=c++1y

It returns: main.cpp:3:10: fatal error: 'Python.h' file not found

Then I found this solution Python.h header file missing on Mac OS X 10.6 then I change the file into

#include <iostream> 
#include <Python/Python.h>
#include <numpy/npy_math.h>

using namespace std; 
int main() 
{ 

   cout << "Hello World" << endl;    // prints value of i 
}

It works, but second problem comes out: main.cpp:3:10: fatal error: 'numpy/npy_math.h' file not found

Ok, then I find the path of numpy and

clang++ main.cpp -std=c++1y -I /Users/nicolas/opt/anaconda3/lib/python3.7/site-packages/numpy/core/include

then, it returns

/Users/nicolas/opt/anaconda3/lib/python3.7/site-packages/numpy/core/include/numpy/npy_common.h:11:10: fatal error: 'Python.h' file not found #include <Python.h>

Can anyone help me?

Nicolas H
  • 535
  • 3
  • 13
  • That would be the right answer from the duplicate: https://stackoverflow.com/a/59074274/5769463 or https://stackoverflow.com/a/16454458/5769463 – ead Feb 26 '21 at 08:07

1 Answers1

1

You can quickfix this by opening npy_common.h and changing #include <Python.h> to either #include <Python/Python.h> or #include <../../Python/Python.h> or whatever is the relative path to that file, or even copy the file Python.h to Users/nicolas/opt/anaconda3/lib/python3.7/site-packages/numpy/core/include/numpy/ folder

The reason the file is not found is because npy_common.h is looking for Python.h in the same directory

Antonin GAVREL
  • 9,682
  • 8
  • 54
  • 81
  • Thanks bro. but then I have to change all the header file one by one, is there any better way to fix this? – Nicolas H Feb 26 '21 at 01:35