Skip to content

1.2

主旨

  • python软件包地址
  • python编译安装
  • 后续不同安装方式不同版本汇聚于此,对比差异并记录

说明

环境说明

## 安装ansible-2.15.2时对python版本的要求
# pwd
/home/opt/ansible
 cat requirements.txt  | grep -v ^#
jinja2 >= 3.0.0
PyYAML >= 5.1  # PyYAML 5.1 is required for Python 3.8+ support
cryptography
packaging
importlib_resources >= 5.0, < 5.1; python_version < '3.10'
resolvelib >= 0.5.3, < 1.1.0  # dependency resolver used by ansible-galaxy
---------------
Python 3.8+ python_version < '3.10'
---------------



10.2.6.106:/home/opt
    python
python版本:
    3.9.10
# python3 -V
Python 3.9.10

软件包地址

官网

openssl

编译安装-python3.9.10

openssl-1.1.1编译安装

此种方式较为耗时,涉及到openssl生产环境的话,要谨慎操作!
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
需要提前安装的软件包
yum -y install zlib*
yum -y install gcc
yum -y install gcc-c++
yum install libffi-devel -y

// 系统默认版本
# openssl version
OpenSSL 1.0.2k-fips  26 Jan 2017


openssl-1.1.1s
./config --prefix=/usr/local/openssl // 指定安装路径
make && make install

// 替换当前系统旧版本
mv /usr/bin/openssl /usr/bin/openssl.old
mv /usr/lib64/openssl /usr/lib64/openssl.old
mv /usr/lib64/libssl.so /usr/lib64/libssl.so.old
ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
ln -s /usr/local/openssl/include/openssl /usr/include/openssl
ln -s /usr/local/openssl/lib/libssl.so /usr/lib64/libssl.so
echo "/usr/local/openssl/lib" >> /etc/ld.so.conf
ldconfig -v // 建立动态链接


// 查看版本
openssl version

# openssl version
OpenSSL 1.1.1s  1 Nov 2022

python3 编译安装

CentOS 7.9 安装python3 pip 3
// python版本:3.9.10
cd Python-3.9.10
## 依据实际情况看是否添加--with-openssl=/usr/local/openssl
./configure --prefix=/usr/local/python3 --with-openssl=/usr/local/openssl
make
make install
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3

yum源安装指定版本python

待补充

问题排错

// python-3.7.2安装报错
  报错:
    提示没有_bz2
  解决:
    将包里面的_bz2.cpython-37m-x86_64-linux-gnu.so复制到自己的/usr/local/python3/lib/python3.7/lib-dynload/

    报错:
        from _ctypes import Union, Structure, Array ModuleNotFoundError: No module named '_ctypes'
    解决:
        yum install libffi-devel -y

    报错:
        WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
    解决:
        编译时候要安装ssl相关的模块
        # ./configure --prefix=/usr/local/python3 --with-openssl=/usr/bin/openssl
        # rpm -qa | grep openssl
    openssl-libs-1.0.2k-21.el7_9.x86_64
    xmlsec1-openssl-1.2.20-7.el7_4.x86_64
    openssl-1.0.2k-21.el7_9.x86_64
        如上,指定本地的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
    解决:
        重新编译openssl,指定编译后的再重试