Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Scrapy python import issue
#1
The Scrapy application just works fine when run from the command line and within the same directory. e.x

When we navigate to the folder and run a spider then that just works fine. While the same command is being used from another directory/folder then it just seems to throw error.

Following is the command that we use from a PHP application
exec('scrapy runspider G:/thevillages/thevillages/spiders/village_spider.py 2>&1', $output);
The errors are as follows
Quote:
0 => "2018-02-12 12:29:08 [scrapy.utils.log] INFO: Scrapy 1.4.0 started (bot: scrapybot)"
1 => "2018-02-12 12:29:08 [scrapy.utils.log] INFO: Overridden settings: {'SPIDER_LOADER_WARN_ONLY': True}"
2 => "Usage"
3 => "====="
4 => " scrapy runspider [options] <spider_file>"
5 => ""
6 => "runspider: error: Unable to load 'G:/thevillages/thevillages/spiders/village_spider.py': No module named thevillages.items"

However I've confirmed the path
>>> os.path.exists('G:/thevillages/thevillages/spiders')
True
>>> os.path.exists('G:/thevillages/thevillages')
True
>>> os.path.exists('G:/thevillages')
True
>>> os.path.exists('G:/thevillages/thevillages/spiders/village_spider.py')
True
I don't really have much experince with python but I do asked on most of the forums and they did advice to ask question on the python-fourm.

Thank you

Ah just solved it by
exec('cd G:/thevillages/thevillages/spiders/ && scrapy runspider village_spider.py &', $output);
Reply
#2
The 2>&1 at end redirected stdout and stderr to file named in $output
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Flask_table module compatibility issue: cannot import name 'Markup' from 'flask' venkateshbalagiri 1 331 Mar-22-2024, 05:07 AM
Last Post: venkateshbalagiri
  Python Scrapy Date Extraction Issue tr8585 1 3,297 Aug-05-2020, 04:32 AM
Last Post: tr8585
  Python Scrapy tr8585 2 2,353 Aug-04-2020, 04:11 AM
Last Post: tr8585
  Python - Scrapy Baggelhsk95 0 2,279 Apr-24-2019, 01:07 PM
Last Post: Baggelhsk95
  Python Scrapy ebay API Baggelhsk95 0 3,199 Nov-21-2018, 11:22 AM
Last Post: Baggelhsk95
  Python scrapy scraped_items Baggelhsk95 2 2,876 Nov-13-2018, 08:30 AM
Last Post: Baggelhsk95
  Python - Scrapy - CSS selector Baggelhsk95 1 5,547 Nov-07-2018, 04:45 PM
Last Post: stranac
  Python - Scrapy - Contains Baggelhsk95 3 4,508 Oct-27-2018, 03:42 PM
Last Post: stranac
  Python - Scrapy Login in Baggelhsk95 3 4,823 Oct-23-2018, 04:24 PM
Last Post: stranac
  Python - Scrapy Ebay Test Baggelhsk95 4 4,315 Oct-16-2018, 12:37 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020