centos6安装Python3

前言

最近折腾SS,需要使用pip3安装,安装pip3前又需要安装python3,python3又需要一堆乱七八糟的问题,由于是使用源码安装,遇到不少问题,在此记录

安装python遇到的问题

一下问题都是在编译或者使用pyhon的时候遇到的,不一而足,在此罗列几个印象深刻的
Python requires an OpenSSL 1.0.2 or 1.1 compatible libssl with X509_VERIFY_PARAM_set1_host().
Can’t connect to HTTPS URL because the SSL module is not available
还有python安装完后,使用pip3 install 的时候遇到下面问题
ModuleNotFoundError: No module named ‘_ctypes’

安装python前装依赖

yum install libffi libffi-devel tcl tk tcl-devel tk-devel sqlite-devel bzip2-devel ncurses-devel xz-devel libuuid-devel

上面yum 装的依赖没有openssl,需要手动编译,原因是yum装的版本不符合python3.9的要求, OpenSSL 1.0.2 or 1.1

安装openssl

根据python要求来能满足就行,用1.1.1版本举例

wget https://www.openssl.org/source/openssl-1.1.1g.tar.gz
tar zxvf openssl-1.1.1g.tar.gz
chmod -R 755 ./openssl-1.1.1g
cd openssl-1.1.1g
chmod -R 755 ./openssl-1.1.1g
./config --prefix=/usr/local/ssl &&make && make install
替换系统老版本的openssl
mv /usr/bin/openssl /usr/bin/openssl.bak
ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl
mv /usr/include/openssl /usr/include/openssl.bak
ln -s /usr/local/ssl/include/openssl /usr/include/openssl
ssl文件夹

编译python3

完成上面准备后,进行python3编译

wget http://www.python.org/ftp/python/3.9.0/Python-3.9.0.tgz
tar zxvf Python-3.3.0.tgz
cd Python-3.3.0
chmod -R 755 ./
./configure --prefix=/usr/local/python3 --with-openssl=/usr/local/ssl/

configure完成后,检查输出,确认下面的3项必须是yes,否则SSL无法编译,后续也无法使用,之前的流程创建bin,lib,include就是为了在这里使用,configure会检查里面的东西是否符合要求

checking for openssl/ssl.h in /usr/local/ssl/… yes
checking whether compiling and linking against OpenSSL works… yes
checking for X509_VERIFY_PARAM_set1_host in libssl… yes

检查通过后

make && make install
ln -s /usr/local/python3/bin/python3 /usr/bin/python3

python3和pip3就安装完成了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值