导入Python 3.4.2时发出错误的请求

时间:2016-12-21 11:47:10

标签: python python-3.x python-requests python-3.4

当我尝试在python 3.4.2中导入请求时,它会给我以下错误:

Python 3.4.2 (v3.4.2:ab2c023a9432, Oct  5 2014, 20:42:22) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
Traceback (most recent call last):
  File "<frozen importlib._bootstrap>", line 2218, in _find_and_load_unlocked
AttributeError: 'module' object has no attribute '__path__'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/requests/packages/__init__.py", line 27, in <module>
    from . import urllib3
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/requests/packages/urllib3/__init__.py", line 8, in <module>
    from .connectionpool import (
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/requests/packages/urllib3/connectionpool.py", line 11, in <module>
    from .exceptions import (
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/requests/packages/urllib3/exceptions.py", line 2, in <module>
    from .packages.six.moves.http_client import (
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/requests/packages/urllib3/packages/six.py", line 203, in load_module
    mod = mod._resolve()
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/requests/packages/urllib3/packages/six.py", line 115, in _resolve
    return _import_module(self.mod)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/requests/packages/urllib3/packages/six.py", line 82, in _import_module
    __import__(name)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/http/client.py", line 69, in <module>
    import email.parser
ImportError: No module named 'email.parser'; 'email' is not a package

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<frozen importlib._bootstrap>", line 2218, in _find_and_load_unlocked
AttributeError: 'module' object has no attribute '__path__'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/requests/__init__.py", line 60, in <module>
    from .packages.urllib3.exceptions import DependencyWarning
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/requests/packages/__init__.py", line 29, in <module>
    import urllib3
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/urllib3/__init__.py", line 8, in <module>
    from .connectionpool import (
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/urllib3/connectionpool.py", line 11, in <module>
    from .exceptions import (
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/urllib3/exceptions.py", line 2, in <module>
    from .packages.six.moves.http_client import (
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/urllib3/packages/six.py", line 203, in load_module
    mod = mod._resolve()
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/urllib3/packages/six.py", line 115, in _resolve
    return _import_module(self.mod)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/urllib3/packages/six.py", line 82, in _import_module
    __import__(name)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/http/client.py", line 69, in <module>
    import email.parser
ImportError: No module named 'email.parser'; 'email' is not a package

我不是要尝试使用像email.parser这样的文件,但它显示错误。我怎样才能解决这个问题?我曾尝试再次安装请求,例如sudo pip3.4 install requestssudo pip3.4 install --upgrade requests。注意:我正在运行macOS Sierra。

1 个答案:

答案 0 :(得分:1)

您有一个名为email.py的本地文件,该文件隐藏了标准库模块。重命名您的文件。