Reputation: 185
I have a persistent issue on the scrapy projects I start.
Wherever I put items.py
, it seems not to be recognized inside the spider. I must be missing something.
My project is named scrapybot
.
To summarize, I have:
scrapybot
├──scrapybot
├──__init__.py
├──core.py
├──custom_middlewares.py
├──middlewares.py
├──pipelines.py
├──settings.py
├──spiders
├──__init__.py
├──amazon_bot.py
├──ebay_bot.py
├──items.py
I want to put items.py
into the spider
folder and import it like this:
>>> from spiders.items import ScrapybotItem
ModuleNotFoundError: No module named 'spiders'
Or like this:
>>> from items import ScrapybotItem
ModuleNotFoundError: No module named 'items'
Do you know why I can't use imports this way? Is this the correct way?
Upvotes: 1
Views: 48
Reputation: 1879
You forgot the name of the top level package: scrapybot
.
Try like this:
>>> from scrapybot.spiders.items import ScrapybotItem
Upvotes: 1