NameError: name 'PROTOCOL_TLS' is not defined - python

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

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.

Related

subprocess.Popen() gives "partially uninitialized module" error [duplicate]

I have problem with requests package. In past requests was working, but today for no reason it stopped working. I am just importing requests and it cause error.
Code:
import requests
Error:
Traceback (most recent call last):
File "d:\programovani\Python\SMSemail\test.py", line 1, in
import requests
File "C:\Users\vitek\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\requests_init_.py", line 43, in
import urllib3
File "C:\Users\vitek\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\urllib3_init_.py", line 11, in
from . import exceptions
File "C:\Users\vitek\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\urllib3\exceptions.py", line 3, in
from .packages.six.moves.http_client import IncompleteRead as httplib_IncompleteRead
File "C:\Users\vitek\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\urllib3\packages\six.py", line 234, in create_module
return self.load_module(spec.name)
File "C:\Users\vitek\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\urllib3\packages\six.py", line 209, in load_module
mod = mod._resolve()
File "C:\Users\vitek\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\urllib3\packages\six.py", line 118, in _resolve
return _import_module(self.mod)
File "C:\Users\vitek\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\urllib3\packages\six.py", line 87, in import_module
import(name)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.3312.0_x64__qbz5n2kfra8p0\lib\http\client.py", line 71, in
import email.parser
File "d:\programovani\Python\SMSemail\email.py", line 1, in
from requests import get
ImportError: cannot import name 'get' from partially initialized module 'requests' (most likely due to a circular import) (C:\Users\vitek\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\requests_init.py)
Screenshot:
What I've tried:
import requests as re
Reinstalling package.
Note: File name is different
What is causing this error? Thank you.
The relevant parts of the traceback and my interpretation:
You're trying to run test.py. One of the imports in it is import requests:
Traceback (most recent call last):
File "d:\programovani\Python\SMSemail\test.py", line 1, in import requests
This results in a (normal) longer chain of imports. Somewhere along the line in the standard library's http.client module there's an import in line 71: import email.parser
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.3312.0_x64__qbz5n2kfra8p0\lib\http\client.py", line 71, in import email.parser
Now trouble starts, because you have a file email.py in the same folder as test.py:
File "d:\programovani\Python\SMSemail\email.py", line 1, in from requests import get ImportError: cannot import name 'get' from partially initialized module 'requests' (most likely due to a circular import)
This alone should be enough to derail the program. So I'm a bit puzzled about the error message you get. I pretty much got the same as you when I tried to reconstruct your situation (one file test.py with import requests and another one named email.py in the same folder) but it ended with:
ModuleNotFoundError: No module named 'email.parser'; 'email' is not a package
You have a from requests import get in email.py, so there is in fact a potential (unintended) circular import (program starts with importing requests and on the way to do that imports (parts of) request again -> circular):
File "d:\programovani\Python\SMSemail\email.py", line 1, in from requests import get
Solution: Renaming email.py should do the job, if I'm not mistaken.

ImportError: Module use of python26.dll conflicts with this version of Python

I use Python 3.2.3
Tonight I tried to install requests from http://docs.python-requests.org/en/latest/ by pip and easy_install, but it doesn't work. I have error when trying to import it. So I decided to use standard library urllib.request and see this error again
That is the traceback:
>>> import requests
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "E:\Python32\lib\site-packages\requests-1.2.0-py3.2.egg\requests\__init__.py", line 52, in <module>
from . import utils
File "E:\Python32\lib\site-packages\requests-1.2.0-py3.2.egg\requests\utils.py", line 12, in <module>
import cgi
File "E:\Python32\lib\cgi.py", line 38, in <module>
from email.parser import FeedParser
File "E:\Python32\lib\email\parser.py", line 12, in <module>
from email.feedparser import FeedParser
File "E:\Python32\lib\email\feedparser.py", line 27, in <module>
from email import message
File "E:\Python32\lib\email\message.py", line 17, in <module>
from email import utils
File "E:\Python32\lib\email\utils.py", line 28, in <module>
import socket
File "E:\Python32\lib\socket.py", line 46, in <module>
import _socket
ImportError: Module use of python26.dll conflicts with this version of Python.
So how can I fix this?
UPD: Solved. It was bug in SublimeREPL, reinstalled that package.
I had a similar problem when I was using PythonXY. The Spyder was not loading and it turns out another software OpenCAD had installed Python2.6 version and that was not letting my Python27.dll to not work. After uninstalling OpenCAD, I was able to run the software.
I was able to troubleshoot by first searching for python26.dll and found that this file was located in the OpenCAD folder location and that made me realize that this software was causing the issue.

Import error with module _ssl for Python 3.3

I am programming in Python 3.3 on the latest version of Ubuntu. I am writing code for a project involving a library that works with Twitter. Here is the output from the terminal I have:
Traceback (most recent call last):
File "tryout.py", line 2, in <module>
import twitter
File "/home/owner/Documents/twitter/__init__.py", line 15, in <module>
from .stream import TwitterStream
File "/home/owner/Documents/twitter/stream.py", line 9, in <module>
from ssl import SSLError
File "/usr/local/lib/python3.3/ssl.py", line 60, in <module>
import _ssl # if we can't import it, let the error propagate
ImportError: No module named '_ssl'
I've been looking around to find a solution for the _ssl error but can't seem to find one that I could follow.

Error "ImportError: no module named mux" in Python

I installed a module one month ago. At that time, I could import the module successfully.
Now, when I import this module, there is an ImportError,
>>> import anuga
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/lili/anuga_core/source/anuga/__init__.py", line 110, in <module> from anuga.file_conversion.urs2nc import urs2nc
File "/home/lili/anuga_core/source/anuga/file_conversion/urs2nc.py", line 12, in <module>
from mux import WAVEHEIGHT_MUX_LABEL, EAST_VELOCITY_LABEL, \
ImportError: No module named mux
How could I solve this problem?
ImportError comes only when the module is not available in the list called sys.path. Since the current operating system is Linux based (I got an idea from the error message /home/lili), it is required to have mux.py in the path (i.e, sys.path). The mux.py file will be exactly similar to the file available in this link.
`https://anuga.anu.edu.au/svn/anuga/trunk/anuga_core/source/anuga/file/mux.py`
All these problems come when the installation of ANUGA is not proper.

Running Pylint on Windows -> ImportError: cannot import from builtins

Maybe someone has a clue about this one. Google, the Logilab.org archives and every other source I tried to determine a solution have turned up empty.
I was trying to get Pylint 2.4 running with PyDev in Eclipse (with Python 2.6) on Windows, but right now I'd be happy simply running pylin at all. I used easy_install to install pylint and it's dependancies. That seemed to work fine. However if I try to run c:\python26\Scripts\pylint.bat , I get the following:
Traceback (most recent call last):
File "C:\Python26\Scripts\pylint", line 5, in <module>
pkg_resources.run_script('pylint==0.24.0', 'pylint')
File "c:\Python26\lib\site-packages\pkg_resources.py", line 489, in run_script
self.require(requires)[0].run_script(script_name, ns)
File "c:\Python26\lib\site-packages\pkg_resources.py", line 1207, in run_script
execfile(script_filename, namespace, namespace)
File "c:\python26\lib\site-packages\pylint-0.24.0-py2.6.egg\EGGINFO\scripts\pylint", line 3, in <module>
from pylint import lint
File "c:\Python26\lib\site-packages\pylint-0.24.0-py2.6.egg\pylint\lint.py", line 31, in <module>
from pylint.checkers import utils
File "c:\Python26\lib\site-packages\pylint-0.24.0py2.6.egg\pylint\checkers\__init__.py", line 44, in <module>
from logilab.astng.utils import ASTWalker
File "c:\Python26\lib\site-packages\logilab_astng-0.22.0py2.6.egg\logilab\astng\__init__.py", line 58, in <module>
from logilab.astng.nodes import *
File "c:\Python26\lib\site-packages\logilab_astng-0.22.0-py2.6.egg\logilab\astng\nodes.py", line 54, in <module>
from logilab.astng.node_classes import Arguments, AssAttr, Assert, Assign, \
File "c:\Python26\lib\site-packages\logilab_astng-0.22.0-py2.6.egg\logilab\astng\node_classes.py", line 27, in <module>
from logilab.astng.bases import (NodeNG, Statement, Instance, InferenceContext,
File "c:\Python26\lib\site-packages\logilab_astng-0.22.0-py2.6.egg\logilab\astng\bases.py", line 28, in <module>
from logilab.common.compat import builtins
ImportError: cannot import name builtins
I mucked around and looked into based.py, but I have no clue what the problem is. My shell path includes C:\python26;c:\Python26\Scripts.
Does this have something to do with lib2to3? Or Python 2.6 compatibility?
Note that I installed pylint using "easy_install pylint", and logilab-common is at the latest 0.56.2.
Thanks!
For me, there is a logilab.common.compat module buried inside the egg "logilab.pylintinstaller-0.15.2-py2.6.egg" in my site-packages folder. Having the logilab_common egg installed, removing the pylintinstaller egg got pylint working in eclipse. I found this out via IPython like so:
In [37]: import logilab.common.compat
In [38]: from logilab.common.compat import builtins
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
C:\Users\Rio\Documents\mcedit\pymclevel\<ipython console> in <module>()
ImportError: cannot import name builtins
In [41]: logilab.common.compat.__file__
Out[41]: 'c:\\python26\\lib\\site-packages\\logilab.pylintinstaller-0.15.2-py2.6.egg\\logilab\\common\\compat.pyc'
Probably you don't have the logilab.common package or the installed version is an old one.
try:
easy_install-2.6 --upgrade logilab-common

Categories

Resources