I am running Python within C, and I can't seem to get the program to compile. I have the following included in the program:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <Python.h>
#include <arrayobject.h>
I am working in VS Code and I have the following tasks.json file:
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc build active file",
"command": "/usr/bin/gcc",
"args": [
"-fdiagnostics-color=always",
"-I/usr/include/**",
"-I~/anaconda3/envs/myenv/include/python3.9/**",
"-I~/anaconda3/envs/myenv/lib/python3.9/site-packages/numpy/core/include/numpy/**",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
When I compile, I get an error:
Starting build...
/usr/bin/gcc -fdiagnostics-color=always -I/usr/include/** -I~/anaconda3/envs/myenv/include/python3.9/** -I~/anaconda3/envs/myenv/lib/python3.9/site-packages/numpy/core/include/numpy/** -g ~/Documents/code/test.c -o ~/Documents/code/test
~/Documents/code/test.c:6:10: fatal error: Python.h: No such file or directory
6 | #include <Python.h>
| ^~~~~~~~~~
compilation terminated.
Build finished with error(s).
I thought that with the -I statements, I'd included everything necessary to run this. What is the best way to include the necessary files? By the way, I also get errors with #include <glib.h>, which should be included with -I/usr/include/**. I'm pretty new to C so I apologize if this is an obvious question.
-I/usr/include/**should perhaps be-I /usr/include/**but you should have-Iinfront of all directories.find /usr/include/ |grep -i python.h?find ~/anaconda3/envs/myenv/include/python3.9 -type f | grep -i python.h?find ~/anaconda3/envs/metagenomics/include/python3.9/ -type f | grep -i python.hyields a result:~anaconda3/envs/myenv/include/python3.9/Python.h-Ito point to.