Scrapy: ImportError: No module named items

jsjc picture jsjc · May 13, 2012 · Viewed 35.3k times · Source

When I try to run scrapy I get this error ImportError: No module named items

I just added in items.py the list of things I want to scrape and in the spider.py I have imported the class with from spider.items import SpiderItem

Dont know why its not loading it...

Package layout is...

./spider
./spider/pipelines.py
./spider/settings.py
./spider/spiders
./spider/spiders/spider_spider.py
./spider/spiders/test.py
./spider/spiders/__init__.py
./spider/middlewares.py
./spider/__init__.py
./spider/items.py

Answer

Nick Craig-Wood picture Nick Craig-Wood · May 13, 2012

From this message on google groups:

Your spider module is named the same as your scrapy project module, so python is trying to import items relative to byub.py spider.

You are facing a common regret of python imports, see http://www.python.org/dev/peps/pep-0328

quicks fixes:

  • rename your spider module to byub_org.py or similar.
  • or use from __future__ import absolute_import in byub.py spider.
  • or rename your project to something like byubbot.