安装Python3.8.6

安装依赖环境

1
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel make
1
yum -y install gcc libffi-devel zlib* openssl-devel libffi-devel zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make

下载Python3.8.6

1
2
cd /usr/local/
wget https://www.python.org/ftp/python/3.8.6/Python-3.8.6.tgz

安装python3.8.6

1、新建安装目录

1
mkdir /usr/local/python3

2、进入到下载路径 解压下载的安装包

1
2
cd /usr/local/
tar -zxvf Python-3.8.6.tgz

3、编译安装需要编译器:

1
yum -y install gcc libffi-devel

4、进入到解压目录,生成编译文件指定安装路径

1
2
cd Python-3.8.6
./configure --prefix=/usr/local/python3 --enable-shared

5、编译 编译成功后,安装

1
2
3
4
make
make install
or
make && make install

6、检查python3.8的编译器:

1
/usr/local/python3/bin/python3

7、建立python3和pip3的软连接

1
2
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3

8、将/usr/local/python3/bin加入PATH 让修改生效

1
vi /etc/profile

加上这个

1
2
3
#配置python
export PYTHON_HOME=/usr/local/python3
export PATH=$PYTHON_HOME/bin:$PATH
1
2
source /etc/profile 
python3 -V

安装Openssl

bug: 使用pip 命令失败
1、错误信息

1
2
3
4
5
6
7
8
9
10
11
12
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Collecting virtualenv
Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/virtualenv/
Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/virtualenv/
Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/virtualenv/
Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/virtualenv/
Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/virtualenv/
Could not fetch URL https://pypi.org/simple/virtualenv/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/virtualenv/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
Could not find a version that satisfies the requirement virtualenv (from versions: )
No matching distribution found for virtualenv
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping

2、原因
系统版本centos6.5,其中openssl的版本为OpenSSL 1.0.1e-fips 11 Feb 2013,而python3.7需要的openssl的版本为1.0.2或者1.1.x,需要对openssl进行升级,并重新编译python3.7.0。yum 安装的openssl 版本都比较低。
3、下载openssl

1
2
3
wget https://www.openssl.org/source/openssl-1.1.1a.tar.gz
tar -zxvf openssl-1.1.1a.tar.gz
cd openssl-1.1.1a

4、编译安装

1
2
3
./config --prefix=/usr/local/openssl no-zlib #不需要zlib
make
make install

5、备份原配置

1
2
mv /usr/bin/openssl /usr/bin/openssl.bak
mv /usr/include/openssl/ /usr/include/openssl.bak

6、新版配置

1
2
3
ln -s /usr/local/openssl/include/openssl /usr/include/openssl
ln -s /usr/local/openssl/lib/libssl.so.1.1 /usr/local/lib64/libssl.so
ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl

7、修改系统配置
写入openssl库文件的搜索路径

1
echo "/usr/local/openssl/lib" >> /etc/ld.so.conf

使修改后的/etc/ld.so.conf生效

1
ldconfig -v

8、查看openssl版本

1
openssl version
1
2
openssl version 提示:
/usr/local/openssl/bin/openssl: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory

假如你的libssl.so.1.1 文件在/usr/local/openssl/lib/下面,可以这样做

1
2
3
find / -name libssl*
ln -s /usr/local/openssl/lib/libssl.so.1.1 /usr/lib64/libssl.so.1.1
ln -s /usr/local/openssl/lib/libcrypto.so.1.1 /usr/lib64/libcrypto.so.1.1

9、重新安装python

1
2
3
cd /usr/local/Python-3.8.6
./configure --prefix=/usr/local/python3 --enable-shared --with-openssl=/usr/local/openssl
make && make install

openssl编译报错记录 安装Perl5

1、报错是这样的

1
Operating system: x86_64-whatever-linux2 You need Perl 5

在执行编译时 ./config --prefix=/usr/local/openssl no-zlib 这一步执行报错了,无法继续编译。
2、解决方式
需要安装 perl-5.34.0.tar.gz
网址连接:https://www.cpan.org/src/README.html
3、安装步骤

1
2
3
4
5
6
7
wget https://www.cpan.org/src/5.0/perl-5.34.0.tar.gz
tar -xzf perl-5.34.0.tar.gz
cd perl-5.34.0
./Configure -des -Dprefix=$HOME/localperl
make
make test
make install

安装完毕重新 ./config --prefix=/usr/local/openssl no-zlib

参考链接

1、linux环境下安装python3.8.68
2、python 安装: WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
3、openssl编译报错记录