Scrapy ----错误ImportError:没有名为tutorial.settings的模块

时间:2018-11-02 13:08:18

标签: python scrapy

草稿文件说

  

Scrapy将在标准位置/etc/scrapy.cfg 的ini样式scrapy.cfg文件中查找配置参数。

我已将scrapy.cfg放在位置/etc/scrapy.cfg并尝试运行 项目根目录scrapy crawl <spider_name>中的tutorial。 我收到错误消息:

Traceback (most recent call last):

  File "/home/user/.local/bin/scrapy", line 11, in <module>
    sys.exit(execute())

  File "/home/user/.local/lib/python2.7/site-packages/scrapy/cmdline.py", line 110, in execute
    settings = get_project_settings()

  File "/home/user/.local/lib/python2.7/site-packages/scrapy/utils/project.py", line 68, in get_project_settings
    settings.setmodule(settings_module_path, priority='project')

File "/home/user/.local/lib/python2.7/site-packages/scrapy/settings/__init__.py", line 292, in setmodule
    module = import_module(module)

File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)

ImportError: No module named tutorial.settings

我在做什么错了?

2 个答案:

答案 0 :(得分:0)

尝试创建tutorial/settings.py。您的输出中包含以下抱怨:ImportError: No module named tutorial.settings,因此,可能需要该文件才能运行。

答案 1 :(得分:0)

我试图遵循本教程https://towardsdatascience.com/a-minimalist-end-to-end-scrapy-tutorial-part-ii-b917509b73f7

,我遇到了同样的问题,我遇到了这个问题,因为文件scrapy.cfg位于文件夹教程中,我将文件移至项目的根目录并解决了问题,因此格式正确将是

scrapy-tutorial-start
---tutorial
   ----settings.py
   ----spider
       ---yourspyders
---venv
---other files
---scrapy.cfg

enter image description here