最新消息:

centos 6 编译安装 python 3.7

OpenSSL admin 4430浏览 0评论

 

  • 因为 centos 6 默认 openssl 版本过低,
  • python 3.7 要求 1.0.1h 以上版本, 所以要单独安装openssl , 否则ssl相关依赖无法使用,错误如下
# /usr/local/python/bin/python3
Python 3.7.0 (default, Jul 13 2018, 17:04:19)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-18)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/python/lib/python3.7/ssl.py", line 98, in <module>
    import _ssl             # if we can't import it, let the error propagate
ModuleNotFoundError: No module named '_ssl'
>>>

安装 openssl

# wget https://www.openssl.org/source/openssl-1.0.2o.tar.gz
# cd openssl-1.0.2o
# ./config --prefix=/usr/local/openssl --openssldir=/usr/local/openssl
# make
# make install

安装 Python 3.7.0

下载Python 3.7.0

# wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz
# cd Python-3.7.0

修改ssl路径

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

安装

# ./configure --prefix=/usr/local/python --enable-optimizations --with-openssl=/usr/local/openssl
# make
# make install
#
# /usr/local/python/bin/python3
Python 3.7.0 (default, Jul 13 2018, 17:48:28)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-18)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
>>> ssl
<module 'ssl' from '/usr/local/python/lib/python3.7/ssl.py'>
>>>

 

转载请注明:爱开源 » centos 6 编译安装 python 3.7

您必须 登录 才能发表评论!