CentOS7.5安装Python3.6.4

安装

  1. 下载依赖

    1
    sudo yum groupinstall -y "Development Tools"
  2. 到python官网找到下载路径

    1
    wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tar.xz
  3. 解压tgz包

    1
    tar -xJf Python-3.6.4.tar.xz
  4. 把python移到/usr/local下面 && 进入python目录

    1
    mv Python-3.6.4 /usr/local && cd /usr/local/Python-3.6.4/
  5. 配置 && 编译 && 安装

    1
    ./configure && make && make install

安装错误

  • make install时候出现zipimport.ZipImportError: can't decompress data; zlib not available
    1、 yum install zlib zlib-devel -y
    2、 make install重新安装

  • make install时候出现ModuleNotFoundError: No module named '_ctypes'
    1、 yum -y install libffi-devel tk-devel
    2、 make install重新安装

  • make install时候出现ImportError: No module named _ssl
    1、查看是否有安装OpenSSL且包完整

    1
    2
    3
    4
    5
    6
    7
    [root@wrx install]# rpm -qa | grep openssl*
    openssh-5.3p1-118.1.el6_8.i686
    openssh-clients-5.3p1-118.1.el6_8.i686
    openssl-1.0.1e-48.el6_8.4.i686
    openssh-server-5.3p1-118.1.el6_8.i686

    #查询结果显示缺少OpenSSL-devel

    2、使用yum安装openssl-devel

    1
    2
    3
    4
    5
    6
    7
    8
    [root@wrx install]# yum install openssl-devel -y
    #查看是否安装成功
    [root@wrx install]# rpm -qa | grep openssl*
    openssh-5.3p1-118.1.el6_8.i686
    openssh-clients-5.3p1-118.1.el6_8.i686
    openssl-1.0.1e-57.el6.i686
    openssh-server-5.3p1-118.1.el6_8.i686
    openssl-devel-1.0.1e-57.el6.i686 #存在

    3、修改Setup.dist(vi Python3.6.4/Modules/Setup.dist)

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    修改后(一共四个地方修改了)
    # Socket module helper for socket(2)
    _socket socketmodule.c

    # Socket module helper for SSL support; you must comment out the other
    # socket line above, and possibly edit the SSL variable:
    #SSL=/usr/local/ssl
    _ssl _ssl.c \
    -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
    -L$(SSL)/lib -lssl -lcrypto

    4、重新编译安装

    1
    ./configure && make && make install

    5、查看ssl模块是否安装成功

    1
    2
    3
    4
    5
    6
    7
    8
    9
    [root@VM_130_127_centos ~]# python3
    Python 3.6.4 (default, Nov 6 2018, 18:10:48)
    [GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import ssl
    >>> print(ssl.PROTOCOL_SSLv23)
    _SSLMethod.PROTOCOL_TLS
    >>>
    #没有报错说明已经安装成功
如果这篇文章对您有帮助,请支持我继续创作!