Ubuntu 16.04 安装python3.6正确顺序(解决ssl错误,pip升级)

发布时间 2023-08-08 10:31:27作者: WenJXUST

0、下载离线python压缩包Python Source Releases | Python.org

1、新建root,并进入root权限(sudo passwd root)(su)

2、升级openssl版本

wget https://www.openssl.org/source/openssl-1.1.0k.tar.gz
tar -zxvf openssl-1.1.0k.tar.gz
cd openssl-1.1.0k
./config
make install  
rm /usr/bin/openssl #删除旧版本
ln -s /usr/local/bin/openssl /usr/bin/openssl #新版本建立链接
cp libssl.so.1.1 /lib/x86_64-linux-gnu  #复制动态库
cp libcrypto.so.1.1 /lib/x86_64-linux-gnu #复制动态库

openssl version 就可以查看新版本了

3、解压安装python3.6

tar -zxvf Python-3.6.0.tgz # 解压

cd Python-3.6.0 # 进入解压后的文件夹

 

修改Modules文件夹里的 setup文件,gedit /Modules/setup,去掉下面三行的注释

207 # Socket module helper for SSL support; you must comment out the other
208 # socket line above, and possibly edit the SSL variable:
209 SSL=/usr/local  #根据下面openssl的include和lib文件所在位置确定这个SSL的值210 _ssl _ssl.c \
211         -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \  #看这里
212         -L$(SSL)/lib -lssl -lcrypto

回到python3.6.0主目录

cd /root/rv1126/Python-3.6.0
./configure # 开始生成makefile
make -j8# 编译
make install # 安装

安装完之后,将默认的python链接指向新安装的这个

cd /usr/bin
rm python 
ln -s /usr/local/python3.6 /usr/bin/python
python -V #查看版本
python3 -V
pip -V
pip3 -V
python -m pip install --upgrade pip