Alex Rivera | Logout

Cannot import either Scrapy's settings module or its scrapy.cfg

Asked 2012-08-31T20:14:56.830
10

This is a quite lengthy post, but after doing extensive research I couldn't find a solution. I have a mixed Django 1.4.1 / Scrapy 0.14.4 project on OSX 10.8 and I control Scrapy with the Django project's manage.py command as described here. For instance, calling

python manage.py scrapy crawl example_spider 

works without a problem. Now I'm at the point where I want to setup the scrapyd web service to deploy my spiders. However, when I execute

python manage.py scrapy server

then I get this exception:

scrapy.exceptions.NotConfigured: Unable to find scrapy.cfg file to infer project data dir

So, apparently Scrapy cannot find the scrapy.cfg file because I don't execute it from within the Scrapy project. The other Scrapy commands work, however, because in my Django project's settings.py I did the following:

sys.path.append('/absolute/path/to/my/Scrapy/project')
os.environ['SCRAPY_SETTINGS_MODULE'] = 'my_scrapy_project_name.settings'

Question 1: Why can't Scrapy detect the scrapy.cfg file in my setup? How can I resolve this?


Since the stuff mentioned above doesn't work, I tried to get the scrapyd server running using just the scrapy command from within my Scrapy project directory. Executing scrapy server from the top-level directory of my Scrapy project yields the following:

$ scrapy server
UserWarning: Cannot import scrapy settings module my_scrapy_project_name.settings
warnings.warn("Cannot import scrapy settings module %s" % scrapy_module)
2012-08-31 21:58:31+0200 [-] Log opened.
2012-08-31 21:58:32+0200 [-] Scrapyd web console available at http://localhost:6800/
2012-08-31 21:58:32+0200 [Launcher] Scrapyd started: max_proc=8,
Edit
Report

1 Answer

3

If you look at the code branch that raises this exception and the definition of the closest_scrapy_cfg function that it calls, the only place scrapy is looking for your scrapy.cfg is in the dir you run the command from and any parent directory. You can maybe run os.chdir in your manage.py, or move your scrapy.cfg to the directory you're running from.

answered 2012-09-11T06:22:13.340

Your Answer