CentOS7 安装 Python3.7 及 SSL 编译错误处理

下载: https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz

解包:tar -zxvf Python-3.7.0.tgz

进入 Python-3.7.0 目录:

    cd Python-3.7.0

 

1. 安装必要的依赖模块:

执行下面的安装指令:

[devalone@nutch Python-3.7.0]$ sudo yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite sqlite-devel readline-devel tk tk-devel gdbm gdbm-devel db4-devel libpcap-devel lzma xz xz-devel libuuid-devel libffi-devel

 

2. 尝试配置、编译

[devalone@nutch Python-3.7.0]$ ./configure --prefix=/usr
[devalone@nutch Python-3.7.0]$ make


编译错误:
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

 

3. 安装 libressl 代替openssl-devel
-------------------------------------------------------------------------------------------------------------------------

libressl 是 openssl 更安全版本分支,生产环境建议使用 libressl 替代 openssl。

 


下载最新稳定版本 2.7.4

https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/libressl-2.7.4.tar.gz

解压:
    tar -zxvf libressl-2.7.4.tar.gz

编译安装:
    [devalone@nutch libressl-2.7.4]$ cd libressl-2.7.4
    [devalone@nutch libressl-2.7.4]$ ./configure --prefix=/usr/local
    [devalone@nutch libressl-2.7.4]$ sudo make install

新建或修改 /etc/ld.so.conf.d/local.conf 配置文件,添加如下内容:
    /usr/local/lib
    
即将 /usr/local/lib 目录加入到模块加载目录。

重新加载共享模块:
    [devalone@nutch Python-3.7.0]$ sudo ldconfig -v

    [devalone@nutch Python-3.7.0]$ openssl version
    LibreSSL 2.7.4

 

4. 安装 libressl 代替openssl-devel
-------------------------------------------------------------------------------------------------------------------------
回到 Python-3.7.0 目录,编辑安装文件 Modules/Setup

删除有关 ssl 编译代码的注释,共 4 行,并修改 SSL 目录为 SSL=/usr/local, 如下所示:

# 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.c \
        -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
        -L$(SSL)/lib -lssl -lcrypto

重新配置、编译:

   [devalone@nutch Python-3.7.0]$ ./configure --prefix=/usr

    [devalone@nutch Python-3.7.0]$ make

编译成功,没有报错,执行安装:
    [devalone@nutch Python-3.7.0]$ sudo make install

测试一下:
    [devalone@nutch Python-3.7.0]$ python3
    Python 3.7.0 (default, Sep  6 2018, 11:51:44)
    [GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux
    Type "help", "copyright", "credits" or "license" for more information.

    >>> import ssl
    >>> import uuid
    >>>

OK.


5. 升级 pip
-------------------------------------------------------------------------------------------------------------------------
[devalone@nutch Python-3.7.0]$ sudo python3 -m pip install --upgrade pip
Collecting pip
  Downloading https://files.pythonhosted.org/packages/5f/25/e52d3f31441505a5f3af41213346e5b6c221c9e086a166f3703d2ddaf940/pip-18.0-py2.py3-none-any.whl (1.3MB)
    100% |████████████████████████████████| 1.3MB 114kB/s
Installing collected packages: pip
  Found existing installation: pip 10.0.1
    Uninstalling pip-10.0.1:
      Successfully uninstalled pip-10.0.1
Successfully installed pip-18.0


OK.

 

6. 安装 mysql-connector, PyMySQL
-------------------------------------------------------------------------------------------------------------------------
[devalone@nutch Python-3.7.0]$ sudo pip3 install mysql-connector
Collecting mysql-connector
  Downloading https://files.pythonhosted.org/packages/59/e0/775bf5fb3dd4c7f9aa6877907d4a96eecca6886c603dedfea6e843e94560/mysql-connector-2.1.6.tar.gz (11.8MB)
    100% |████████████████████████████████| 11.8MB 40kB/s
Installing collected packages: mysql-connector
  Running setup.py install for mysql-connector ... done
Successfully installed mysql-connector-2.1.6

 


[devalone@nutch Python-3.7.0]$ sudo pip3 install PyMySQL
Collecting PyMySQL
  Downloading https://files.pythonhosted.org/packages/a7/7d/682c4a7da195a678047c8f1c51bb7682aaedee1dca7547883c3993ca9282/PyMySQL-0.9.2-py2.py3-none-any.whl (47kB)
    100% |████████████████████████████████| 51kB 225kB/s
Collecting cryptography (from PyMySQL)
  Downloading https://files.pythonhosted.org/packages/59/32/92cade62c645756a83598edf56289e9b19aae5370642a7ce690cd06bc72f/cryptography-2.3.1-cp34-abi3-manylinux1_x86_64.whl (2.1MB)
    100% |████████████████████████████████| 2.1MB 83kB/s
Collecting cffi!=1.11.3,>=1.7 (from cryptography->PyMySQL)
  Downloading https://files.pythonhosted.org/packages/51/7b/d1014289d0578c3522b2798b9cb87c65e5b36798bd3ae68a75fa1fe09e78/cffi-1.11.5-cp37-cp37m-manylinux1_x86_64.whl (421kB)
    100% |████████████████████████████████| 430kB 77kB/s
Collecting idna>=2.1 (from cryptography->PyMySQL)
  Downloading https://files.pythonhosted.org/packages/4b/2a/0276479a4b3caeb8a8c1af2f8e4355746a97fab05a372e4a2c6a6b876165/idna-2.7-py2.py3-none-any.whl (58kB)
    100% |████████████████████████████████| 61kB 108kB/s
Collecting asn1crypto>=0.21.0 (from cryptography->PyMySQL)
  Downloading https://files.pythonhosted.org/packages/ea/cd/35485615f45f30a510576f1a56d1e0a7ad7bd8ab5ed7cdc600ef7cd06222/asn1crypto-0.24.0-py2.py3-none-any.whl (101kB)
    100% |████████████████████████████████| 102kB 135kB/s
Collecting six>=1.4.1 (from cryptography->PyMySQL)
  Downloading https://files.pythonhosted.org/packages/67/4b/141a581104b1f6397bfa78ac9d43d8ad29a7ca43ea90a2d863fe3056e86a/six-1.11.0-py2.py3-none-any.whl
Collecting pycparser (from cffi!=1.11.3,>=1.7->cryptography->PyMySQL)
  Downloading https://files.pythonhosted.org/packages/8c/2d/aad7f16146f4197a11f8e91fb81df177adcc2073d36a17b1491fd09df6ed/pycparser-2.18.tar.gz (245kB)
    100% |████████████████████████████████| 256kB 86kB/s
Installing collected packages: pycparser, cffi, idna, asn1crypto, six, cryptography, PyMySQL
  Running setup.py install for pycparser ... done
Successfully installed PyMySQL-0.9.2 asn1crypto-0.24.0 cffi-1.11.5 cryptography-2.3.1 idna-2.7 pycparser-2.18 six-1.11.0

 
————————————————
版权声明:本文为CSDN博主「devalone」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/devalone/article/details/82459276

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值