search

Home  >  Q&A  >  body text

python - scrapy无法初始化项目

在交互环境


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)
PHPzPHPz2891 days ago410

reply all(3)I'll reply

  • 阿神

    阿神2017-04-17 18:02:50

    Is there something wrong with the environment setup?
    Check whether there is an installation package in your problematic code:

    >>> import pip
    >>> installed_packages = pip.get_installed_distributions()
    >>> installed_packages_list = sorted(["%s==%s" % (i.key, i.version)
    ...      for i in installed_packages])
    >>> print(installed_packages_list)

    Method taken from:
    http://stackoverflow.com/questions/739993/how-can-i-get-a-list-of-locally-installed-python-modules

    reply
    0
  • PHPz

    PHPz2017-04-17 18:02:50

    I checked Scrapy’s Release notes and found

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

    That is to say, the latest version of scrapy does not use the pydispatch module, but uses the pydispatcher module
    So maybe you are not using the latest scrapy?
    As a solution, I suggest you use virtualenv to build an independent python environment. Reinstall the latest scrapy in this environment.
    or reinstall scrapy directly in the system

    reply
    0
  • 高洛峰

    高洛峰2017-04-17 18:02:50

    pip install PyDispatcher

    reply
    0
  • Cancelreply