the ssl module in Python is not available錯誤解決

在使用pip安裝pymongo的過程當中報錯,提示以下:python

1 $ pip3 install pymongo 2 pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available. 3 Collecting pymongo 4   Could not fetch URL https://pypi.python.org/simple/pymongo/: There was a problem confirming the ssl certificate: Can't connect to HTTPS URL because the SSL module is not available. - skipping
5   Could not find a version that satisfies the requirement pymongo (from versions: ) 6 No matching distribution found for pymongo

這是因爲缺乏ssl模塊,進入python中驗證。linux

$ python Python 3.7.0a3 (default, Jan 10 2018, 14:36:35) [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] 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/lib/python3.7/ssl.py", line 100, in <module>
    import _ssl             # if we can't import it, let the error propagate
ModuleNotFoundError: No module named '_ssl'
>>>

緣由找到:缺乏openssl-devel包socket

$ rpm -qa | grep openssl openssl-1.0.2k-8.el7.x86_64 xmlsec1-openssl-1.2.20-7.el7_4.x86_64 openssl-libs-1.0.2k-8.el7.x86_64

解決方法:fetch

一、安裝openssl-devel包ui

$ sudo yum install -y openssl-devel

二、從新編譯安裝pyhtonspa

修改Setup配置code

$ vi Modules/Setup 找到 # Socket module helper for socket(2) #_socket socketmodule.c

# 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 _ssl.c \ # -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \ # -L$(SSL)/lib -lssl -lcrypto
改成 # Socket module helper for socket(2)
_socket socketmodule.c # 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 _ssl.c \ -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \ -L$(SSL)/lib -lssl -lcrypto

編譯安裝orm

./configure &&  sudo make && sudo make install

驗證:xml

$ python Python 3.7.0a3 (default, Jan 10 2018, 15:13:22) [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import ssl >>>

安裝pymongoblog

$ sudo /usr/local/bin/pip3 install pymongo Collecting pymongo Downloading pymongo-3.6.0.tar.gz (581kB) 100% |████████████████████████████████| 583kB 28kB/s Installing collected packages: pymongo Running setup.py install for pymongo ... done Successfully installed pymongo-3.6.0

安裝完成

相關文章
相關標籤/搜索