环境:
python:3.6.9
ubuntu:16.04.5
新拿到远程服务器,配置环境需要用到pipenv,在 pip install pipenv的时候,出现了以下错误:
Retrying (Retry(total=2, connect=None, read=None,
redirect=None, status=None)) after connection broken by
'SSLError("Can't connect to HTTPS URL because the SSL
module is not available.",)': /simple/pipenv/
...
...
Could not fetch URL https://pypi.org/simple/pip/: There was a
problem confirming the ssl certificate:
HTTPSConnectionPool(host='pypi.org', port=443): Max
retries exceeded with url: /simple/pip/ (Caused by
SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)) - skipping
原因
系统缺少python的_ssl依赖包,在输入编译命令make test 后,发现有报错:
No module named :
'_ssl'、'_tkinter'、'_lzma'等
启动python,导入ssl模块发现也报错
$ python
Python 3.6.9 (default, Oct 21 2020, 08:00:24)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python3.6/ssl.py", line 101, in
import _ssl # if we can't import it, let the error propagate
ModuleNotFoundError: No module named '_ssl'
解决:
安装openssl,等python依赖包
sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev
按照以下命令依次执行
./configure
sudo make
sudo make install
pip3 install package_name
相关链接:https://stackoverflow.com/questions/41328451/ssl-module-in-python-is-not-available-when-installing-package-with-pip3