python.h :no such file or directory error in Qtcreator

标签 python c++ qt-creator

我正在使用 Qtcreator 设计一些表单,我想在表单中单击按钮时调用 python 脚本。但是当我使用时:

#include <Python.h>

我收到以下错误:

python.h: no such file or directory

我浏览了许多链接,这些链接给出了导致此错误的原因,但我无法理解。我刚刚开始使用 Qt 创建者,我不知道如何处理它。与此错误相关的所有链接都提到了包含 python 库的路径、对 .pro 文件进行更改,但我不知道如何通过 Qt 创建者来完成此操作以及到底要做什么。当我在终端中运行命令“locate Python.h”时,我得到以下输出:

/usr/include/python2.7/Python.h

所以我在我的 debian 上安装了 python-dev。您能否详细告诉我如何解决这个问题。我正在寻找一种包含这些库的方法,以便我可以以类似的方式使用其他库,如 QtGUI、tango 等。

最佳答案

要在 QT 项目中正确包含 pyhton 的 header ,请执行以下操作:

  1. 在头文件中添加#include

    #include <Python.h>
    
  2. 在项目的 .pro 文件中插入

    CONFIG += no_keywords # Python redefines some qt keywords
    INCLUDEPATH += /usr/include/python<version>
    LIBS += -lpython<version>
    
  3. 根据thisslots 替换为 Q_SLOTS 等等...

希望对你有帮助

关于python.h :no such file or directory error in Qtcreator,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27365966/

相关文章:

python - 在 Next.js 中运行 python 脚本

c++ - 轻松打印详细的调试输出?

c++ - 超过 120000 个元素的数组崩溃

android - Qt Creator 在 Android 8.0 (LG G6) 上不显示日志消息

c++ - QT Creator 简单应用

python - 根据索引在python中拆分字符串

python - 用于 Transformer DNN 模型的基于时间序列的数据的位置编码

python - keras 回调列表生成错误 : 'tuple' object has no attribute 'set_model'

c++ - 在 OS X 上安装 Boost 1.48.0

c++ - 使用任何 QT 小部件打印特定文件夹中的文件名