问题
I have installed scrapy with pip install scrapy
. But in python shell I am getting an 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
Also for scrapy shell, I am getting the same error. So I uninstalled scrapy with autoremove and installed it again but no change. Am I missing out on something?
回答1:
It looks like that you've defined a module called urllib.py
which shadows built-in urllib
module. Remove/rename the file.
来源:https://stackoverflow.com/questions/30077534/importerror-cannot-import-name-unwrap