【问题标题】:Python, C++ & Sublime Text 2: Python.h: No such file or directoryPython、C++ 和 Sublime Text 2:Python.h:没有这样的文件或目录
【发布时间】:2014-08-21 09:52:34
【问题描述】:

想用一些 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 开发是最新的

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

-I/usr/include/python2.7/

尝试将此添加到包下 C++.sublime-text 文件中的构建命令中,但只是破坏了构建系统。救命啊,我是个无能的小人

【问题讨论】:

  • +1 称自己为无知的小人
  • 这个命令在你的系统上的输出是什么:sudo updatedb &amp;&amp; locate Python.h
  • ~/Downloads/Python-2.7.5/Include/Python.h /usr/include/python2.7/Python.h /usr/local/include/python2.7/Python.h 感谢您的宝贵时间
  • 你看过类似的问题吗? stackoverflow.com/questions/11041299/…

标签: python c++ sublimetext2


【解决方案1】:

在 Sublime-Text/Packages/C++(你可以通过首选项->浏览包->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}"]

Windows

"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}"]

保存,您就可以“增压”您的代码了 ;)

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

【讨论】:

    猜你喜欢
    • 2021-05-31
    • 1970-01-01
    • 2012-06-17
    • 2021-08-27
    • 2017-12-13
    • 1970-01-01
    • 2013-08-03
    • 2013-11-05
    • 1970-01-01
    相关资源
    最近更新 更多