ubuntu 16.04 python 3.x 安装OpenSSL

错误提示:

Can't connect to HTTPS URL because the SSL module is not available.

连接HTTPS时,提示SSL不可用

测试

# 进入python
$ python3  # or python3.6
# 导入SSL模块
>>> import ssl

如果出现下面提示,则Python不支持SSL。

错误提示

解决方案

下载文件

  • OpenSSL

    • $ wget http://www.openssl.org/source/openssl-1.0.2e.tar.gz
  • Python3.6 - 选择需要的版本

    • $wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tgz

安装

OpenSSL

# 解压文件
tar xvzf openssl-1.0.2e.tar.gz
# 进入目录
$ ./config --prefix=/usr/local/openssl --openssldir=/usr/local/openssl
$ make
$ make test
$ sudo make install

Python

进入目录
#解压
$ tar xvzf Python-3.6.2.tgz
$ cd Python-3.6.2
修改安装配置

使用VIM打开文件Modules/Setup.dist文件,搜索SSL,取消四行注释

$ vim Modules/Setup.dist

修改配置

开始安装

完成上面操作就可以安装了,执行下面3行代码

$ ./configure
$ make
$ sudo make install

完成!

不出意外已经安装完成,下面检测一下。

  • 进入python

    $ python3
    
  • 导入SSL模块

    >>> import ssl
    

导入成功

没有报错就已经成功了!

posted @ 2018-04-29 17:31  看门的大爷  阅读(1067)  评论(0编辑  收藏  举报