【问题标题】:C++ embedding PythonC++ 嵌入 Python
【发布时间】:2014-04-03 15:33:29
【问题描述】:

我想用 C++ 运行 Python 脚本。

在我的书中,有以下内容:

#include <Python.h>
... at main function some calls

但是在编译编译器时找不到 Python 头文件。

我该如何解决这个问题?

【问题讨论】:

  • 取决于您使用的平台。在 linux 上,您需要安装 python-devel 软件包(如何安装也取决于特定的发行版)。
  • 在基于 Debian 的发行版上,该软件包实际上称为 python-dev
  • 我有 linux mint,应该怎么调用呢?
  • 还没用,找不到头文件...我下载了python-dev ..但是找不到头文件...

标签: python c++ include embed


【解决方案1】:

在 Linux Mint sudo apt-get install python-dev 上应该可以完成这项工作。这将获取并安装 python 开发文件。

这应该将包含文件放在/usr/include/python2.7/,因此您需要将-l /usr/include/python2.7/ 添加到您的编译器标志中。

`

【讨论】:

  • 我安装了这个,但是在编译时:martin@ThinkPad ~/Schreibtisch $ g++ pytest.cpp -o pytest pytest.cpp:1:20: 致命错误:Python.h: Datei oder Verzeichnis nicht gefunden #include ^ 编译终止。
  • 还没用,找不到头文件...我下载了python-dev ..但是找不到头文件...
  • 路径见上文。
  • 不工作...我添加了路径链接器,但仍然是同样的错误,但在此文件夹中 Python.h 文件位于...
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-01-16
  • 2020-12-23
  • 1970-01-01
  • 2020-12-12
  • 1970-01-01
相关资源
最近更新 更多