ModuleNotFoundError: No module named 'XXXXspider.settings'

来源:7-2 CrawlSpider源码分析-新建CrawlSpider与settings配置

慕妹1389429

2020-03-17

Traceback (most recent call last):
File “/usr/local/python3/lib/python3.7/runpy.py”, line 193, in _run_module_as_main
"main", mod_spec)
File “/usr/local/python3/lib/python3.7/runpy.py”, line 85, in _run_code
exec(code, run_globals)
File “/home/my_env/twitter_spider/lib/python3.7/site-packages/scrapyd/runner.py”, line 40, in
main()
File “/home/my_env/twitter_spider/lib/python3.7/site-packages/scrapyd/runner.py”, line 37, in main
execute()
File “/home/my_env/twitter_spider/lib/python3.7/site-packages/scrapy/cmdline.py”, line 114, in execute
settings = get_project_settings()
File “/home/my_env/twitter_spider/lib/python3.7/site-packages/scrapy/utils/project.py”, line 69, in get_project_settings
settings.setmodule(settings_module_path, priority=‘project’)
File “/home/my_env/twitter_spider/lib/python3.7/site-packages/scrapy/settings/init.py”, line 294, in setmodule
module = import_module(module)
File “/home/my_env/twitter_spider/lib/python3.7/importlib/init.py”, line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File “

老师 我用了scrapydweb来部署爬虫 但是在上传的时候提示这个错误 但是我在setting里已经按照6-2课添加了
BASE_DIR = os.path.dirname(os.path.abspath(os.path.dirname(file)))
sys.path.insert(0, os.path.join(BASE_DIR, ‘XXXXspider’))

还是不能识别settings文件 在爬虫项目文件中import settings 也提示找不到模块 但是在pycharm中mark sourse root之后就可以了,我应该怎么操作呢

写回答

1回答

bobby

2020-03-18

有了sys.path.insert(0, os.path.join(BASE_DIR, ‘XXXXspider’))就不需要 source root了,你有没有试过在cmd中是否能运行main文件?

0
0

Scrapy打造搜索引擎 畅销4年的Python分布式爬虫课

带你彻底掌握Scrapy,用Django+Elasticsearch搭建搜索引擎

5796 学习 · 6290 问题

查看课程