python3 and scrapy path

1、python3 program, how to import modules from different directories
2、How do I get path information of scrapy
enter image description here
3、from RUGplatform.custom_module.rule_module import CrawlRule, ParserRule
ImportError: No module named 'RUGplatform'

1 answer

  • answered 2018-07-12 03:04 LWX

    my solution:

    import os
    import sys
    sys.path.append('/'.join(os.path.split(os.path.realpath(__file__))[0].split('/')[0:-2]))<br>
    from RUGplatform.custom_module.rule_module import CrawlRule, ParserRule
    

    Is there a more elegant solution? For example, the solution from scrapy framework