fatal error: Python.h: No such file or directory | Linux系统 搜索 Python.h 位置

原因:swig C++ 代码转 python

运行命令:

gcc -c -fpic example.c example_wrap.c -I/usr/local/include/python2.0

报错如下:

example_wrap.c:154:21: fatal error: Python.h: No such file or directory
compilation terminated.


因此,我需要找到自己 Linux 服务器的 可用 Python.h


(方法一)找到 系统 python 下的 Python.h

# 去系统下发现可用 Python
cd /usr/include/

find | grep python

# 可以发现这里有  python2.7 和  python3.5

drwxr-xr-x   2 root root  12288 Aug 10  2018 python2.7/
lrwxrwxrwx   1 root root     10 Nov 29  2017 python3.5 -> python3.5m/
drwxr-xr-x   2 root root   4096 Feb  2  2018 python3.5m/

cd /usr/include/python3.5

# 就可以发现 Python.h 文件
find | grep Python.h

# 输出如下
./Python.h

  • 然后正确执行代码(安排Python):
gcc -c -fpic example.c example_wrap.c -I/usr/include/python3.5

便可以顺利完成转化了(该任务可能和您的不一样呢);

(方法二)到 Anaconda3 目录下 寻找含有 Python.h 的 环境


cd /home/moli/anaconda3

~/anaconda3$ find | grep Python.h

./envs/torch11/include/python3.7m/Python.h
./envs/nice/include/python3.6m/Python.h
./envs/n2n366/include/python3.6m/Python.h
./envs/pix2pix/include/python3.6m/Python.h
./envs/tf20/include/python3.6m/Python.h
./include/python3.6m/Python.h

  • 使用 conda 下的 Python
gcc -c -fpic example.c example_wrap.c -I/home/moli/anaconda3/include/python3.6m
  • 2
    点赞
  • 1
    收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:Age of Ai 设计师:meimeiellie 返回首页
评论 2

打赏作者

墨理学AI

不必打赏,关注博主公众号即可

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

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

打赏作者

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

抵扣说明:

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

余额充值