在scrapy中导入错误urllib.parse

时间:2015-07-16 14:29:28

标签: python python-2.7 web-scraping scrapy urllib2

我正在尝试使用scrapy。我做了pip install scrapy。我的python版本是2.7.9。安装后我在终端输入scrapy时出现以下错误:

  File "/usr/bin/scrapy", line 7, in <module>
    from scrapy.cmdline import execute
  File "/usr/lib/python2.7/site-packages/scrapy/__init__.py", line 48, in <module>
    from scrapy.spiders import Spider
  File "/usr/lib/python2.7/site-packages/scrapy/spiders/__init__.py", line 10, in <module>
    from scrapy.http import Request
  File "/usr/lib/python2.7/site-packages/scrapy/http/__init__.py", line 10, in <module>
    from scrapy.http.request import Request
  File "/usr/lib/python2.7/site-packages/scrapy/http/request/__init__.py", line 12, in <module>
    from scrapy.utils.url import escape_ajax
  File "/usr/lib/python2.7/site-packages/scrapy/utils/url.py", line 9, in <module>
    from six.moves.urllib.parse import (ParseResult, urlunparse, urldefrag,
ImportError: No module named urllib.parse

我知道scrapy需要python 2.7但是在python 3中引入了urllib.parse,之前它是urlparse。看看错误似乎错误是在scrapy安装中。该怎么办?我已经多次卸载并重新安装了碎片。但问题仍然存在。

1 个答案:

答案 0 :(得分:2)

我们可以使用python 2和python 3的单独导入。

try:
    from urllib.parse import urlparse
except ImportError:
    from urlparse import urlparse

从这里得到这个答案。 no module named urllib.parse (How should I install it?)