CentOS7.9 Python3.6.8 升级Python3.9.4

 

CentOS7.9 默认python版本

如下:

# python  -V
Python 2.7.5
# python3 -V
Python 3.6.8

 

安装依赖包libffi-devel

 如果不安装会报错:/Python-3.9.4/Modules/_ctypes/_ctypes.c:107:17: fatal error: ffi.h: No such file or directory

#  yum install libffi-devel

 

安装依赖包zlib-devel  

如果不安装,安装会报错:

zipimport.ZipImportError: can't decompress data; zlib not available

# yum install zlib-devel.x86_64

 

 安装依赖包libressl

如果不安装

python使用ssl模块import ssl会报错:

>>> import ssl
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/python39/lib/python3.9/ssl.py", line 98, in <module>
    import _ssl             # if we can't import it, let the error propagate
ModuleNotFoundError: No module named '_ssl

 

编译会报错:

  Python requires an OpenSSL 1.0.2 or 1.1 compatible libssl with X509_VERIFY_P

 安装步骤如下:

Python requires an OpenSSL 1.0.2 or 1.1 compatible libssl with X509_VERIFY_P

python3.7以上 可以使用libressl代替openssl

源码编译安装libressl如下:

# 下载并解压源码包
wget https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/libressl-3.0.2.tar.gz
tar -zxvf libressl-3.0.2.tar.gz

# 编译安装
cd libressl-3.0.2

./configure --prefix=/usr/local/libressl
make -j8 & sudo make install

# 创建软连接代替openssl

mv /usr/bin/openssl /usr/bin/openssl.bak
ln -s /usr/local/libressl/bin/openssl /usr/bin/openssl
echo /usr/local/libressl/lib >> /etc/ld.so.conf.d/libressl-3.0.2.conf

#  查看版本
ldconfig -v | grep openssl

# 验证是否安装完成
openssl version

# 引入
export LDFLAGS="-L/usr/local/libressl/lib"
export PKG_CONFIG_PATH="/usr/local/libressl/lib/pkgconfig"

 

 Python3.9.4 安装

 

# 下载python包
 wget https://www.python.org/ftp/python/3.9.4/Python-3.9.4.tgz 

# 解压、编译安装
tar -xvf Python-3.9.4.tgz 
cd Python-3.9.4
make
make install 

#



 

备份并替换默认python3版本 

# 备份并替换默认python3版本
mv /usr/bin/python3 /usr/bin/python3.bak
ln -s /usr/local/python39/bin/python3 /usr/bin/python3

mv /usr/bin/pip3 /usr/bin/pip3.bak
ln -s /usr/local/python39/bin/pip3 /usr/bin/pip3

 

 

 

 

 


 

posted @ 2023-02-10 17:30  i学笔记  阅读(731)  评论(0编辑  收藏  举报