我正在使用 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 ,请执行以下操作:
在头文件中添加
#include
#include <Python.h>
在项目的
.pro
文件中插入CONFIG += no_keywords # Python redefines some qt keywords INCLUDEPATH += /usr/include/python<version> LIBS += -lpython<version>
根据this将
slots
替换为Q_SLOTS
等等...
希望对你有帮助
关于python.h :no such file or directory error in Qtcreator,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27365966/