Note that there are some explanatory texts on larger screens.

plurals
  1. POCannot import either Scrapy's settings module or its scrapy.cfg
    primarykey
    data
    text
    <p>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 <code>manage.py</code> command as described <a href="https://stackoverflow.com/a/9197627/1125413">here</a>. For instance, calling </p> <pre><code>python manage.py scrapy crawl example_spider </code></pre> <p>works without a problem. Now I'm at the point where I want to setup the <code>scrapyd</code> web service to deploy my spiders. However, when I execute </p> <pre><code>python manage.py scrapy server </code></pre> <p>then I get this exception:</p> <pre><code>scrapy.exceptions.NotConfigured: Unable to find scrapy.cfg file to infer project data dir </code></pre> <p>So, apparently Scrapy cannot find the <code>scrapy.cfg</code> file because I don't execute it from within the Scrapy project. The other Scrapy commands work, however, because in my Django project's <code>settings.py</code> I did the following:</p> <pre><code>sys.path.append('/absolute/path/to/my/Scrapy/project') os.environ['SCRAPY_SETTINGS_MODULE'] = 'my_scrapy_project_name.settings' </code></pre> <p><strong>Question 1:</strong> Why can't Scrapy detect the <code>scrapy.cfg</code> file in my setup? How can I resolve this?</p> <hr> <p>Since the stuff mentioned above doesn't work, I tried to get the <code>scrapyd</code> server running using just the <code>scrapy</code> command from within my Scrapy project directory. Executing <code>scrapy server</code> from the top-level directory of my Scrapy project yields the following:</p> <pre><code>$ 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, runner='scrapyd.runner' 2012-08-31 21:58:32+0200 [-] Site starting on 6800 2012-08-31 21:58:32+0200 [-] Starting factory &lt;twisted.web.server.Site instance at 0x101dd3d88&gt; </code></pre> <p>The server is running without a problem, however, the <code>settings.py</code> file of my Scrapy project cannot be found because the respective environment variable is not set anymore. That's why I do the following in my terminal:</p> <pre><code>export PYTHONPATH=/absolute/path/to/my/Scrapy/project export SCRAPY_SETTINGS_MODULE=my_scrapy_project_name.settings </code></pre> <p>Unfortunately, these two commands have no effect. Whenever I execute <code>scrapy server</code> (or any other Scrapy command), I get the message that Scrapy cannot import its project's settings module.</p> <p>My <code>scrapy.cfg</code> only has the following content at the moment:</p> <pre><code>[settings] default = my_scrapy_project_name.settings [deploy:scrapyd] url = http://localhost:6800/ project = my_scrapy_project_name </code></pre> <p>When I try to deploy my Scrapy project to the <code>scrapyd</code> server, it seems to work at first, but then I realized that none of the spiders have been uploaded, probably because the settings file could not be detected. Here is the console output:</p> <pre><code>$ scrapy deploy scrapyd -p my_scrapy_project_name /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site- packages/scrapy/utils/project.py:17: UserWarning: Cannot import scrapy settings module my_scrapy_project_name.settings warnings.warn("Cannot import scrapy settings module %s" % scrapy_module) Building egg of event_crawler-1346531706 'build/lib' does not exist -- can't clean it 'build/bdist.macosx-10.6-intel' does not exist -- can't clean it 'build/scripts-2.7' does not exist -- can't clean it zip_safe flag not set; analyzing archive contents... Deploying event_crawler-1346531706 to http://localhost:6800/addversion.json Server response (200): {"status": "ok", "project": "my_scrapy_project_name", "version": "1346531706", "spiders": 0} </code></pre> <p><strong>Question 2:</strong> How to do the correct export of the path and environment variable above so that this warning disappears?</p> <p><strong>Question 3:</strong> Since the <code>scrapyd</code> server seems to work fine though, how can I upload my spiders correctly? </p> <p>Many thanks in advance!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload