0

Using VSCode (which I'm quite new to) on Ubuntu 20.04, I wish to build a C-extension (actually C++ extension) to Python.

I'm trying to build the following MWE:

#include <numpy/arrayobject.h>
int main() {return 0;}

However the build fails on #include <numpy/arrayobject.h> with the error

/usr/include/numpy/ndarrayobject.h:11:10: fatal error: Python.h: No such file or directory

I do have python3.9-dev installed, and my c_cpp_properties.json is supposed to contain the relevant path to include:

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "/usr/include/python3.9",
            ],
            "defines": [],
            "compilerPath": "/usr/bin/clang",
            "cStandard": "c17",
            "cppStandard": "c++14",
            "intelliSenseMode": "linux-clang-x64"
        }
    ],
    "version": 4
}

This question was supposedly answered plenty of times in the past, and yet nothing works for me from any answer I found.

Thank you for your help.

7
  • c_cpp_properties.json has nothing to do with the compiler. The file you need to edit to affect the compiler is tasks.json. Commented Oct 3, 2023 at 21:05
  • @john Can you elaborate on the required change? Can I make g++ look inside /usr/include/python3.9 by default? Commented Oct 3, 2023 at 21:08
  • 2
    Your tasks.json file contains arguments passed to the compiler g++. Judging by your question above, you need to add the argument "-I/usr/include/python3.9" Commented Oct 3, 2023 at 21:09
  • @john Thank you for your help. Adding that argument in the beginning of the "args" list, I now get another errors: 1. /usr/include/python3.9/object.h:430: undefined reference to `_Py_Dealloc'. 2. /usr/include/numpy/__multiarray_api.h:1466: undefined reference to `PyImport_ImportModule' Commented Oct 3, 2023 at 21:14
  • 1
    Well those are link errors. Again the solution will be one or more additional arguments to tasks.json to link with the correct libraries. Not knowing much about python I have no idea what those might be. Probably worth a new question, and this time include your tasks.json file in the question. Commented Oct 3, 2023 at 21:17

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.