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


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

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中驗證。

$ 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包

$ 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

解決方法:

1、安裝openssl-devel包

$ sudo yum install -y openssl-devel

2、重新編譯安裝pyhton

修改Setup配置

$ 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

編譯安裝

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

驗證:

$ 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
>>>

安裝pymongo

$ 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

安裝完成

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM