0

I would like call python functions from C++. I am using Ubuntu 20.04 and have python 3.8 installed. The path where Python.h is located is /usr/include/python3.8/Python.h, which I found using the command line sudo find / -iname python.h in the terminal. In order to get started I tried to run the easiest code in code::blocks:

#include <Python.h>
#include <iostream>

using namespace std;

int main()
{
    cout<<"starting interpreter."<<endl;
    Py_Initialize();
    PyRun_SimpleString("Hallo from Python");
    Py_Finalize();
    return 0;
}

I get the error message:

fatal error: Python.h: No such file or directory|

My question is: Which libraries do I have to include and how do I include these in code::blocks? For a detailed description I would be very thankful.

Greetings, Ben

Ben
  • 1
  • there's the recommended way: compile c code for python with python itself (using distutils) or you probably can just change your include to something like `#include ` since `Python.h` isnt directly in your include paths if you havent done anything to them – AntiMatterDynamite May 08 '21 at 10:31
  • I have tried to include ```#include ```. However, I get the following error message: ```fatal error: cpython/initconfig.h: No such file or directory```. How can I proceed ? – Ben May 08 '21 at 10:40
  • this is already discussed at https://stackoverflow.com/questions/3286448/calling-a-python-method-from-c-c-and-extracting-its-return-value – thirdeye May 14 '21 at 04:33

0 Answers0