ImportError: cannot import name unwrap

ImportError: cannot import name unwrap

我已经用 pip install scrapy 安装了 scrapy。但是在 python shell 我得到一个 ImportError:

>>> from scrapy.spider import Spider
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/scrapy/__init__.py", line 56, in <module>
    from scrapy.spider import Spider
  File "/usr/local/lib/python2.7/dist-packages/scrapy/spider.py", line 7, in <module>
    from scrapy.http import Request
  File "/usr/local/lib/python2.7/dist-packages/scrapy/http/__init__.py", line 10, in <module>
    from scrapy.http.request import Request
  File "/usr/local/lib/python2.7/dist-packages/scrapy/http/request/__init__.py", line 15, in <module>
    from scrapy.utils.url import escape_ajax
  File "/usr/local/lib/python2.7/dist-packages/scrapy/utils/url.py", line 10, in <module>
    import urllib
  File "urllib.py", line 1, in <module>
    import urllib2, json
  File "/usr/lib/python2.7/urllib2.py", line 112, in <module>
    from urllib import (unwrap, unquote, splittype, splithost, quote,
ImportError: cannot import name unwrap

对于 scrapy shell,我也遇到了同样的错误。所以我用 autoremove 卸载了 scrapy 并再次安装它但没有改变。我错过了什么吗?

看起来您已经定义了一个名为 urllib.py 的模块,它 shadows 内置 urllib 模块。 Remove/rename 文件。