使用python时,我无法导入twython。安装似乎很好,但由于某种原因,我在下面得到以下错误。我第一次尝试导入时出现错误" ImportError:无法导入名称ProtocolError"并且每次后续尝试都会导致以下错误" ImportError:无法导入名称证书"。可能有一个简单的解决方案,但我不知所措。
In [1]: from twython import Twython
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-d48648e29d1e> in <module>()
----> 1 from twython import Twython
/Users/Rush/build/bdist.macosx-10.5-x86_64/egg/twython/__init__.py in <module>()
/Users/Rush/build/bdist.macosx-10.5-x86_64/egg/twython/api.py in <module>()
/Users/Rush/anaconda/lib/python2.7/site-packages/requests/__init__.py in <module>()
56 pass
57
---> 58 from . import utils
59 from .models import Request, Response, PreparedRequest
60 from .api import request, get, head, post, patch, put, delete, options
/Users/Rush/anaconda/lib/python2.7/site-packages/requests/utils.py in <module>()
23 from . import __version__
24 from . import certs
---> 25 from .compat import parse_http_list as _parse_list_header
26 from .compat import (quote, urlparse, bytes, str, OrderedDict, unquote, is_py2,
27 builtin_str, getproxies, proxy_bypass)
/Users/Rush/anaconda/lib/python2.7/site-packages/requests/compat.py in <module>()
5 """
6
----> 7 from .packages import charade as chardet
8
9 import sys
/Users/Rush/anaconda/lib/python2.7/site-packages/requests/packages/__init__.py in <module>()
1 from __future__ import absolute_import
2
----> 3 from . import urllib3
/Users/Rush/anaconda/lib/python2.7/site-packages/requests/packages/urllib3/__init__.py in <module>()
14
15
---> 16 from .connectionpool import (
17 HTTPConnectionPool,
18 HTTPSConnectionPool,
/Users/Rush/anaconda/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.py in <module>()
31 from .packages.ssl_match_hostname import CertificateError
32 from .packages import six
---> 33 from .connection import (
34 DummyConnection,
35 HTTPConnection, HTTPSConnection, VerifiedHTTPSConnection,
/Users/Rush/anaconda/lib/python2.7/site-packages/requests/packages/urllib3/connection.py in <module>()
39 )
40 from .packages.ssl_match_hostname import match_hostname
---> 41 from .util import (
42 assert_fingerprint,
43 resolve_cert_reqs,
/Users/Rush/anaconda/lib/python2.7/site-packages/requests/packages/urllib3/util/__init__.py in <module>()
16 )
17
---> 18 from .retry import Retry
19 from .url import (
20 get_host,
/Users/Rush/anaconda/lib/python2.7/site-packages/requests/packages/urllib3/util/retry.py in <module>()
2 import logging
3
----> 4 from ..exceptions import (
5 ProtocolError,
6 ConnectTimeoutError,
ImportError: cannot import name ProtocolError
#####################################################################################
#####################################################################################
#####################################################################################
In [2]: from twython import Twython
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-2-d48648e29d1e> in <module>()
----> 1 from twython import Twython
/Users/Rush/build/bdist.macosx-10.5-x86_64/egg/twython/__init__.py in <module>()
/Users/Rush/build/bdist.macosx-10.5-x86_64/egg/twython/api.py in <module>()
/Users/Rush/anaconda/lib/python2.7/site-packages/requests/__init__.py in <module>()
56 pass
57
---> 58 from . import utils
59 from .models import Request, Response, PreparedRequest
60 from .api import request, get, head, post, patch, put, delete, options
/Users/Rush/anaconda/lib/python2.7/site-packages/requests/utils.py in <module>()
22
23 from . import __version__
---> 24 from . import certs
25 from .compat import parse_http_list as _parse_list_header
26 from .compat import (quote, urlparse, bytes, str, OrderedDict, unquote, is_py2,
ImportError: cannot import name certs
&#13;
答案 0 :(得分:3)
这似乎是这个问题的一种表现:https://github.com/kennethreitz/requests/issues/2028
我通过重新安装请求解决了这个问题:
pip uninstall requests
然后
pip install requests