linux安装thefuck报gcc错误

报错代码

今天心血来潮打算在自己的centos服务器安装大名鼎鼎的thefuck
根据官网的指示,安装方法非常简单,只需要
pip install thefuck
安装完成后再进行简单地配置就可以大功告成了

但是在linux上安装时,却报了如下错误

    gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -DPSUTIL_POSIX=1 -DPSUTIL_SIZEOF_PID_T=4 -DPSUTIL_VERSION=573 -DPSUTIL_LINUX=1 -I/usr/include/python3.6m -c psutil/_psutil_common.c -o build/temp.linux-x86_64-3.6/psutil/_psutil_common.o
    psutil/_psutil_common.c:9:20: fatal error: Python.h: No such file or directory
     #include <Python.h>
                        ^
    compilation terminated.
    error: command 'gcc' failed with exit status 1
    
    ----------------------------------------
Command "/usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-dwgphu9_/psutil/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-a1_xzgs6-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-dwgphu9_/psutil/

报错分析

该段报错光复制最下面一行是搜不到结果的,其关键在于上面的

gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -DPSUTIL_POSIX=1 -DPSUTIL_SIZEOF_PID_T=4 -DPSUTIL_VERSION=573 -DPSUTIL_LINUX=1 -I/usr/include/python3.6m -c psutil/_psutil_common.c -o build/temp.linux-x86_64-3.6/psutil/_psutil_common.o
    psutil/_psutil_common.c:9:20: fatal error: Python.h: No such file or directory
     #include <Python.h>
                        ^
    compilation terminated.
    error: command 'gcc' failed with exit status 1

仔细观察可以看出,该段代码的大意是执行了一个超级长的gcc,在执行过程中读取到psutil/_psutil_common.c文件时,有一个Python.h文件没有找到,导致了gcc报错

所以问题的解决方案在于Python.h文件


解决方案

安装python-dev或者python3-dev

Debian或者Ubuntu

sudo apt-get install python-dev 
sudo apt-get install python3-dev

CentOS / Fedora / RedHat

sudo yum install python-devel  
sudo yum install python3-devel 

后面再进行正常地配置就可以使用了
在shell输入

vim ~/.bashrc

在最后一行键入

eval "$(thefuck --alias fuck)"

最后的fuck可以改成任何你想要的关键词 :wq推出后执行如下命令即可使之运行

source ~/.bashrc
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值