[Python] How to link python.h and matplotlibcpp.h in Visual Studio 2019?

Discussão em 'Python' iniciado por Stack, Julho 6, 2025.

  1. Stack

    Stack Membro Participativo

    From a related post, one installed package matplotlib-cpp through microsoft / vcpkg . However, when running a simple example,

    #include "matplotlibcpp.h"
    namespace plt = matplotlibcpp;
    int main() {
    plt::plot({1,3,2,4});
    plt::show();
    }


    an error returned stating that

    Error C1083 Cannot open include file: 'Python.h': No such file or directory Examples
    ..\vcpkg\installed\x64-windows\include\matplotlibcpp.h 5


    I have tried the methods in:


    1. can't include Python.h in visual studio


    2. psycopg: Python.h: No such file or directory and Cygwin gcc issue - cannot find Python.h (which didn't apply since vs managed python environment itself, and there wasn't python-dev option)


    3. A very similiar post C++: matplotlibcpp.h and Python.h linker error also indicated the same issue in Ubuntu environment.

    In matplotlibcpp.h file, it mentioned that

    // Python headers must be included before any system headers, since
    // they define _POSIX_C_SOURCE
    #include <Python.h>


    What did it mean? How to link python.h and a matplotlibcpp.h in Visual Studio 2019?


    Updates: I was able to locate "Python.h" and "numpy/arrayobject.h" in MS python folder. However, when I manually added those three ".h" files into the project header folder, the issue wasn't resolved. Especially, when I manually fixed the locations in "matplotlibcpp.h", the "Python.h" in ""numpy/arrayobject.h" still could not be located.

    Continue reading...

Compartilhe esta Página