3

I am trying to import Biopython modules on my Mac terminal but its throwing following error. It will be very helpful if someone could help me fix this issue.

>>> from Bio import SeqIO
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/Bio/SeqIO/__init__.py", line 317, in <module>
    from Bio._py3k import basestring
  File "/Library/Python/2.7/site-packages/Bio/_py3k/__init__.py", line 235, in <module>
    from urllib2 import urlopen, Request
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 94, in <module>
    import httplib
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 1230, in <module>
    import ssl
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 133, in <module>
    PROTOCOL_SSLv23 = PROTOCOL_TLS
NameError: name 'PROTOCOL_TLS' is not defined

Thank you!!!

ShadowRanger
  • 143,180
  • 12
  • 188
  • 271
Ambuj Kumar
  • 31
  • 1
  • 2

1 Answers1

1

PROTOCOL_TLS was added in 2.7.13.

Oddly, it looks like your error is in the ssl module itself which should know about this constant; I'm guessing something is terribly wrong with the _ssl module that provides the C interface to OpenSSL. I know Macs and OpenSSL have been a headache for the CPython developers, but I can't give you much more than this.

Try doing import _ssl and making sure _ssl.PROTOCOL_TLS exists and that _ssl comes from a sane file system location (somewhere near the ssl module itself); if it doesn't, your _ssl module is a problem. It's possible you've got a pre-2.7.13 _ssl module somehow included in your sys.path, even as a post-2.7.13 ssl module is being loaded, which expects to find PROTOCOL_TLS in _ssl, and explodes when it can't be found.

ShadowRanger
  • 143,180
  • 12
  • 188
  • 271
  • Thank you so much!! I had whole bunch of unnecessary things set in bashrc file. I removed following and it worked -> #export PATH="/usr/local/bin:$PATH" #export PATH="/usr/local/opt/hdf5@1.8.18/bin:$PATH" – Ambuj Kumar May 24 '18 at 02:34
  • Is `/usr/local/lib/python2.7/lib-dynload/_ssl.so` a wrong path for _ssl module? – kinORnirvana Nov 20 '18 at 15:21
  • @kinORnirvana: That looks fine (there are multiple possible paths, but that looks like a typical one). The issue would be determining whether `_ssl` has the constant its supposed to have. – ShadowRanger Nov 20 '18 at 16:00
  • 2
    I was too tired of this investigation and finished it by editing `/usr/lib/python2.7/ssl.py ` (add `PROTOCOL_TLS = 2` line). After that the problem (of running pip) was solved (but I'm not sure I din't broke something). – kinORnirvana Nov 20 '18 at 16:21