欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程语言 > python >内容正文

python

python没有那个文件或目录_fatal error: Python.h: 没有那个文件或目录 解决方法

发布时间:2023/12/10 python 43 豆豆
生活随笔 收集整理的这篇文章主要介绍了 python没有那个文件或目录_fatal error: Python.h: 没有那个文件或目录 解决方法 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

今天安装scrapy

先说下环境 Ubuntu16.04 系统默认Python 2.7.12 (default, Nov 19 2016, 06:48:10) ,安装过anaconda(很关键,里面有好多系统包,也是为什么此工具不十分依赖系统环境的原因,否则单独装matplotlib也是难弄!!!)

在系统安装过程中,总是到twisted时报错,因为是源码安装的,所以系统要进行编译,但是找不到python.h文件!!!

报错如下

creating build/temp.linux-x86_64-2.7/src

creating build/temp.linux-x86_64-2.7/src/twisted

creating build/temp.linux-x86_64-2.7/src/twisted/test

x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c src/twisted/test/raiser.c -o build/temp.linux-x86_64-2.7/src/twisted/test/raiser.o

src/twisted/test/raiser.c:4:20: fatal error: Python.h: 没有那个文件或目录

compilation terminated.

error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

网上找了一下,没有能解决这个问题的

有的是用安装 python-dev 但是系统安装不上,因为不满足依赖,主要是版本不一致,系统不允许安装的问题

有人安装 sudo aptitude install python-dev

但是也是无法安装成功的。

我后来就find / -name Python.h 2>/dev/null 这个是看到别人的,也是这个启发了我。

由于我安装过anaconda

找到了这个文件,于是抱着试试看的态度

sudo cp -R /home/john/tools/anaconda2/pkgs/python-2.7.13-heccc3f1_16/include/python2.7/ /usr/include/

为什么是/usr/include/位置, 何以在报错内容发现这个路径的!

然后安装,我去竟然可以!!! 呵呵呵~~~~

希望你也能成功!

总结

以上是生活随笔为你收集整理的python没有那个文件或目录_fatal error: Python.h: 没有那个文件或目录 解决方法的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。