小弟最近在學習 scrapy
在使用 items.py 的時候碰到 ModuleNotFoundError
使用 pycharm 進行 improt 的時候並不會報錯
執行 scrapy crawl 的時候才會產生錯誤訊息
想上來版上詢問
以下是檔案目錄結構、發生錯誤的那行 code 以及錯誤訊息
PS C:\Users\bear\Desktop\traveler\crawler> scrapy crawl huashan
Traceback (most recent call last):
File "C:\Users\bear\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users\bear\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "C:\Users\bear\Desktop\traveler\venv\Scripts\scrapy.exe\__main__.py", line 7, in <module>
File "c:\users\bear\desktop\traveler\venv\lib\site-packages\scrapy\cmdline.py", line 144, in execute
cmd.crawler_process = CrawlerProcess(settings)
File "c:\users\bear\desktop\traveler\venv\lib\site-packages\scrapy\crawler.py", line 280, in __init__
super().__init__(settings)
File "c:\users\bear\desktop\traveler\venv\lib\site-packages\scrapy\crawler.py", line 152, in __init__
self.spider_loader = self._get_spider_loader(settings)
File "c:\users\bear\desktop\traveler\venv\lib\site-packages\scrapy\crawler.py", line 146, in _get_spider_loader
return loader_cls.from_settings(settings.frozencopy())
File "c:\users\bear\desktop\traveler\venv\lib\site-packages\scrapy\spiderloader.py", line 67, in from_settings
return cls(settings)
File "c:\users\bear\desktop\traveler\venv\lib\site-packages\scrapy\spiderloader.py", line 24, in __init__
self._load_all_spiders()
File "c:\users\bear\desktop\traveler\venv\lib\site-packages\scrapy\spiderloader.py", line 51, in _load_all_spiders
for module in walk_modules(name):
File "c:\users\bear\desktop\traveler\venv\lib\site-packages\scrapy\utils\misc.py", line 80, in walk_modules
mod = import_module(path)
File "C:\Users\bear\AppData\Local\Programs\Python\Python310\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 992, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1004, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'crawler'
PS C:\Users\bear\Desktop\traveler\crawler>
因為你起始路徑就已經在 Crawler 裡面了
所以自然找不到 crawler 這個資料夾
應該直接改成:
from traveler.items import ExhibitionItem
即可