Linux安装Python3.7.X报错问题解决办法实录

Linux安装Python3.7.X报错问题解决办法实录

1、获取python3.7.4安装包

官网下载:https://www.python.org/downloads/release/python-374/

2、解压

tar -zxvf Python-3.7.4.tgz 

3、创建编译目录并编译安装

cd Python-3.7.4/
./configure --prefix=/usr/local/python37
make && make install

问题出现了!

缺少Openssl引发的问题

在这里插入图片描述
详细如下:

Could not build the ssl module!
Python requires an OpenSSL 1.0.2 or 1.1 compatible libssl with X509_VERIFY_PARAM_set1_host().
LibreSSL 2.6.4 and earlier do not provide the necessary APIs, https://github.com/libressl-portable/portable/issues/381

原因是因为Linux系统中的Openssl问题,可以按照提示安装Openssl1.0.2来解决
我这里安装的版本是Openssl1.0.2K
官方下载地址:
http://www.linuxfromscratch.org/blfs/view/7.7/postlfs/openssl.html

tar -zxvf openssl-1.0.2k.tar.gz 
cd openssl-1.0.2k/
./config --prefix=/usr/local/openssl
make && make install

完成后检测openssl是否安装正常

openssl version

在这里插入图片描述
我们可以看到,现在Linux系统中已经存在openssl,那重新安装Python3.7.4,这次指定openssl的安装路径

cd Python-3.7.4/
./configure --prefix=/usr/local/python37  --with-openssl=/usr/local/openssl
make && make install

新问题出现了!Σ(っ °Д °;)っ

缺少zlib引发的问题

在这里插入图片描述
详细如下:

zipimport.ZipImportError: can’t decompress data; zlib not available
make: *** [install] Error 1

原因是因为缺少zlib依赖,那就老方法,缺啥装啥
下载zlib源码包并安装,我这里安装的版本是1.2.11
官网下载地址:
http://www.zlib.net/

tar -zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11/
./configure
make && make install

安装完成后,继续按照过程安装Python3.7.4

cd Python-3.7.4/
./configure --prefix=/usr/local/python37  --with-openssl=/usr/local/openssl
make && make install

新问题又出现了!(╯‵□′)╯︵┻━┻

缺少libffi-devel引发的问题

在这里插入图片描述
详细如下:

ModuleNotFoundError: No module named ‘_ctypes’
make: *** [install] Error 1

出现这个问题,原因是Python3.7系列需要提前安装libffi-devel
知道了问题所在那就好办了,安装走起
官网下载地址:
http://www.rpmfind.net/linux/rpm2html/search.php?query=libffi-devel

rpm -ivh libffi-devel-3.0.13-19.el7.x86_64.rpm

有时候会报错,注意!如果有下图出现的情况,代表并没有安装依赖成功!
在这里插入图片描述
那就需要采取忽略依赖安装,并等待安装完成即可

rpm -ivh libffi-devel-3.0.13-19.el7.x86_64.rpm --nodeps

安装好libffi-devel依赖后,继续尝试安装Python3.7.4

cd Python-3.7.4/
./configure --prefix=/usr/local/python37  --with-openssl=/usr/local/openssl
make && make install

谢天谢地!终于看到了安装成功的页面 o(╥﹏╥)o
在这里插入图片描述

4、创建软连接

在创建软连接前,先看看系统原本的软连接

ls -n /usr/bin/python

在这里插入图片描述
可以看到系统默认是指向python2,我们需要把指向python2的软连接删掉,换成我们新安装的python3

rm /usr/bin/python
ln -s /usr/local/python37/bin/python3 /usr/bin/python

最后检测python版本
在这里插入图片描述
至此,python3.7.4就安装成功!

本次测试安装环境:
Linux版本:Centos 7.4
发行编号:3.10.0-693.el7.x86_64

  • 4
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值