21

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
jsjc
  • 1,003
  • 2
  • 12
  • 24
  • your middle sencence makes no sense. you probably have a problem with (relative) imports. you should post your package layout, then maybe someone can help you. – mata May 13 '12 at 09:48

6 Answers6

28

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.
Kul-Tigin
  • 16,728
  • 1
  • 35
  • 64
Nick Craig-Wood
  • 52,955
  • 12
  • 126
  • 132
  • 1
    Thanks Nick but I have already found that and tried to solve it... and that was not the issue or at least I am not getting a solution... – jsjc May 13 '12 at 13:24
4

I happend to face this problem because my spider name is the same with the scrapy project.

Just rename the spider name will make it.

hahakubile
  • 6,978
  • 4
  • 28
  • 18
  • Had the same issue, I renamed the spider name file different than the project and it worked – delpo Apr 02 '18 at 17:59
2

Without renaming any files, change from spider.items import SpiderItem to from .. import items and refer to the item as items.SpiderItem in your code.

Fan Jin
  • 400
  • 5
  • 12
2

It's a good solution to rename your spider module.

But don't forget to delete the related *.pyc file after renaming, considering that the *.pyc file plays a role like cache.

henry zhu
  • 561
  • 4
  • 6
1

Sorry for necroposting. Try put in file ./spider/__init__.py

that

 import items
while1pass
  • 340
  • 5
  • 15
0

You are missing the following line after your import statements in your spider.py file.

class ProjectnamegoeshereSpider(BaseSpider):

Theodis Butler
  • 136
  • 2
  • 9