Computer Science/TIL

[C++/Cython] macOS에서 Python.h: No such file or directory 에러 해결 방법

morijwana 2021. 6. 28. 23:06
#include <Python.h> // fatal error: Python.h: No such file or directory

헤더를 아래와 같이 변경해주면 된다.

#include <Python/Python.h>

헤더를 변경했는데 Python 버전이 2.7이라 불편하다면, 경로에 /Library/Frameworks/Python.framework/Versions/(설치되어 있는 파이썬 버전)/Headers를 추가해주면 된다. vscode에서는 c_c__properties.json 파일의 includePath, macFrameworkPath 부분을 아래처럼 수정해주면 된다.

{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "${workspaceFolder}/**",
                "/Library/Frameworks/Python.framework/Versions/3.8/Headers"
            ],
            "defines": [],
            "macFrameworkPath": [
                "/Library/Frameworks/Python.framework/Versions/3.8/Headers",
                "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
            ],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "c11",
            "cppStandard": "c++98",
            "intelliSenseMode": "macos-clang-x64"
        }
    ],
    "version": 4
}