ubuntu 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

 导入成功

没有报错就已经成功了!

猜你喜欢

转载自www.cnblogs.com/jiap/p/8971467.html