Python, C++ & Sublime Text 2: Python.h: 没有这样的文件或目录

Python, C++ & Sublime Text 2: Python.h: No such file or directory

本文关键字:Python 文件 C++ Sublime Text      更新时间:2023-10-16

想用一些python扩展我的c++。

文件正在构建:

#include <Python.h>
错误:

[DIR]:1:20: fatal error: Python.h: No such file or directory
#include <Python.h>

我正在使用sublime text 2来构建我的代码

sudo apt-get install python-dev 
locate Python.h
/usr/include/python2.7/Python.h

^python dev是最新的

发现一些谷歌链接谈论包括构建路径或其他东西,但这不是我的强项

-I/usr/include/python2.7/

尝试将此添加到c++中的构建命令中。软件包下的Sublime-text文件,但却破坏了构建系统。救命,我是一个无知的小男人

在Sublime-Text/Packages/c++(可以通过preferences->browse Packages -> c++找到)中编辑名为c++ .sublime-build的文件。在'cmd'行:

UBUNTU

"cmd": ["g++", "${file}", "-o", "${file_path}/${file_base_name}"]

添加'-I/usr/include/python2.7 -lpython2.7'如下(/usr/include/python2.7是Python.h目录)

"cmd": ["g++", "-I/usr/include/python2.7", "${file}", "-lpython2.7", "-o", "${file_path}/${file_base_name}"]

"cmd": ["g++", "${file}", "-o", "${file_path}/${file_base_name}"]

添加'-I/Python27/include'如下(/Python27/include是Python.h目录)

"cmd": ["g++", "${file}", "-I/Python27/include", "-L/Python27/libs", "-lpython27", "-o", "${file_path}/${file_base_name}"]

保存,你就可以"增压"你的代码了;)

注意:我对建筑代码之类的东西很糟糕,所以这可能不是解决问题的最优雅的方法