scrapy无法初始化项目

Rancho
  • 57

在交互环境


import scrapy    # 成功

但是在终端 scrapy 新建项目就出错了

Traceback (most recent call last):
  File "/usr/local/bin/scrapy", line 7, in <module>
    from scrapy.cmdline import execute
  File "/usr/local/lib/python2.7/dist-packages/scrapy/cmdline.py", line 9, in <module>
    from scrapy.crawler import CrawlerProcess
  File "/usr/local/lib/python2.7/dist-packages/scrapy/crawler.py", line 15, in <module>
    from scrapy.signalmanager import SignalManager
  File "/usr/local/lib/python2.7/dist-packages/scrapy/signalmanager.py", line 2, in <module>
    from pydispatch import dispatcher
ImportError: No module named pydispatch

可是, pydispatch包已经有了呀!

$ pip install --upgrade pydispatch

Requirement already up-to-date: pydispatch in /usr/local/lib/python2.7/dist-packages
Requirement already up-to-date: colorama>=0.2.7 in /usr/local/lib/python2.7/dist-packages (from pydispatch)
Requirement already up-to-date: six>=1.5.2 in /usr/local/lib/python2.7/dist-packages (from pydispatch)
回复
阅读 5.3k
4 个回答
twowwidd
  • 2
新手上路,请多包涵

我查了下Scrapy的 Release notes,发现

The previously bundled scrapy.xlib.pydispatch library was deprecated and replaced by pydispatcher.

也就是说最新版本的scrapy是没有用到 pydispatch 模块的,用的是 pydispatcher 模块
所以可能你用的不是最新的scrapy?
解决方法的话,我建议你用virtualenv搭建一个独立的python环境,在这个环境下重新安装最新的scrapy.
或者直接在系统里重新安装scrapy

董小贱
  • 4
新手上路,请多包涵

from scrapy.xlib.pydispatch import dispatcher 我是用这个方法引入的,正常运行,希望对你有用

宣传栏