C调用Python报错:fatal error: Python.h: No such file or directory

参考文章:Linux GCC常用命令

我的Ubuntu系统上有Python,但是gcc找不到Python.h

问题:

        C调用Python时报错:

fatal error: Python.h: No such file or directory
 #include <Python.h>

分析:

网上各种解决方案,常见的有:

第一种:

 sudo apt-get install python-dev   # for python2.x installs
sudo apt-get install python3-dev  # for python3.x installs

sudo apt-get install python3.6-dev

sudo apt-get install python-dev

第二种:

1.可以先查看一下含python-devel的包

    yum search python | grep python-devel

2.64位安装python-devel.x86_64,32位安装python-devel.i686,我这里安装:

    sudo yum install python-devel.x86_64

3. 进入/usr/include/python2.7看一下现在有没有Python.h,版本不同目录名不同,我这里是2.7版本。其实也可以看到很多.h文件,python需要库或头文件都在这个地方。

均不奏效!!!

解决方案

1. 将c代码中的 #include <Python.h> 改为: #include <python2.7/Python.h>

2. gcc的编译命令为: 

       gcc [c文件名] -lpython2.7 -o test
       例如:  
       gcc c_python.c -lpython2.7 -o test

3.执行文件:./test

问题解决!

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

风情客家__

原创不易,觉得好的话给个打赏哈

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值