首页 > 解决方案 > 如何在 Visual Studio 2019 中链接 python.h 和 matplotlibcpp.h?

问题描述

相关帖子中,一个通过microsoft/vcpkg安装了包 matplotlib-cpp。但是,在运行一个简单的示例时,

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

返回一个错误,指出

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

我已经尝试过以下方法:

  1. 不能在 Visual Studio 中包含 Python.h

  2. psycopg:Python.h:没有这样的文件或目录Cygwin gcc 问题 - 找不到 Python.h(这不适用,因为 vs 托管 python 环境本身,并且没有 python-dev 选项)

  3. 一个非常相似的帖子C++:matplotlibcpp.h 和 Python.h 链接器错误在 Ubuntu 环境中也表明了同样的问题。

matplotlibcpp.h文件中,它提到

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

这是什么意思?如何在 Visual Studio 2019 中链接 python.h 和 matplotlibcpp.h?


更新:我能够在 MS python 文件夹中找到“Python.h”和“numpy/arrayobject.h”。但是,当我手动将这三个“.h”文件添加到项目头文件夹中时,问题并没有解决。特别是,当我手动修复“matplotlibcpp.h”中的位置时,仍然无法找到“numpy/arrayobject.h”中的“Python.h”。

标签: pythonc++visual-studiomatplotlibheader

解决方案


推荐阅读