Python.h:没有这样的文件或目录 [英] Python.h: No such file or directory

查看:1617
本文介绍了Python.h:没有这样的文件或目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近在运行Ubuntu 12.04 LTS的Macbook Pro上安装了KDevelop 4 for C ++开发。

I recently installed KDevelop 4 for C++ development on my Macbook Pro running Ubuntu 12.04 LTS.

我想在我的C ++代码中嵌入Python应用程序。为此,需要包括Python.h头文件。所以,我做到了。

I want to embed Python application in my C++ code. To do that, one needs to include the Python.h header file. So, I did that.

#include <iostream>
#include <Python.h>

int main(int argc, char **argv) {
    Py_Initialize();
    return 0;
}

但是,在运行时,我从IDE收到以下响应: p>

However, on running, I received the following response from the IDE:

fatal error: Python.h: No such file or directory

但是,我很快就发现了问题。我没有下载python-dev包。所以,我做到了。我再次跑了,但同样的错误又在那里。所以,我认为这必须是一个问题的头文件不包括在KDevelop。因此,我将相关文件夹添加到包含路径,KDevelop立即通过删除上面代码中第二个include语句下的红色下划线来识别。

However, I found the problem soon enough. I hadn't downloaded the python-dev package. So, I did that. I ran again but the same error was there again. So, I thought it must be an issue with the header file not being included by KDevelop. Thus, I added the relevant folder to the include path and KDevelop immediately recognized that by removing the red underline beneath the second include statement in the code above.

问题仍然存在。我得到相同的错误。感谢您能提供的任何帮助或输入: - )

But still, the problem remains. I get the same error. Would appreciate any help or inputs you guys can provide :-)

非常感谢。

我没有提到的细节是KDevelop正在使用cmake为我的项目。我猜我的问题发生的原因是因为cmake不知道合适的编译器和链接器路径。

Some details that I missed mentioning earlier are that KDevelop is using cmake for my project. I guess the reason my problem is occurring is because cmake doesn't know the appropriate compiler and linker paths. I would appreciate any help in setting the correct paths for cmake.

推荐答案

在CMakeLists.txt中,尝试添加以下内容:

In your CMakeLists.txt, try adding the following:

find_package(PythonLibs REQUIRED)
include_directories(${PYTHON_INCLUDE_DIRS})
target_link_libraries(<your exe or lib> ${PYTHON_LIBRARIES})

有关命令的详细信息,请运行:

For details of the commands, run:

cmake --help-module FindPythonLibs
cmake --help-command find_package
cmake --help-command include_directories
cmake --help-command target_link_libraries

这篇关于Python.h:没有这样的文件或目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆