【问题标题】:error while using Python.h使用 Python.h 时出错
【发布时间】:2015-03-02 18:09:19
【问题描述】:

我刚刚写了一个简单的 c 代码来检查 Python.h 是否工作

#include<Python.h>
#include<stdio.h>
int main()
{
    printf("this is a python header file included programm\n");
    return 0;
}

显然它并没有做太多。问题是当我尝试用 gcc 编译它时会出错。

foo.c:1:19: fatal error: Python.h: No such file or directory.

然后我尝试检查我的 python-dev 包是否安装了 Python.h 或没有使用 locate。

$locate Python.h

这给了我路径

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

现在,很明显我的系统上有 Python.h 头文件。如何让它工作?

【问题讨论】:

  • 您是否尝试将-I/usr/include/python2.7 添加到您的CFLAGS

标签: python python-2.7 ubuntu python-3.x cython


【解决方案1】:

尝试安装:

sudo apt-get install python-dev

编译时运行如下:

gcc -Wall -I/usr/include/python2.7 -lpython2.7  nameOfProgram.c -o name 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-09-29
    • 2013-07-15
    • 2020-05-12
    • 1970-01-01
    • 2016-09-17
    • 2015-09-30
    • 2021-02-26
    • 2021-12-19
    相关资源
    最近更新 更多