main.py文件在ssh里面可以执行,但是到了pycharm就不行了

来源:2-7 spider文件的编写(2)

enhiko

2018-10-13 18:39

我的main.py文件
from scrapy import cmdline
cmdline.execute('scrapy crawl douban_spider'.split())

我的报错信息:

ssh://crow@192.168.150.128:22/usr/bin/python3 -u /home/crow/demon-lab/douban/douban/main.py

Traceback (most recent call last):

  File "/home/crow/demon-lab/douban/douban/main.py", line 2, in <module>

    cmdline.execute('scrapy crawl douban_spider'.split())

  File "/usr/local/lib/python3.5/dist-packages/scrapy/cmdline.py", line 110, in execute

    settings = get_project_settings()

  File "/usr/local/lib/python3.5/dist-packages/scrapy/utils/project.py", line 68, in get_project_settings

    settings.setmodule(settings_module_path, priority='project')

  File "/usr/local/lib/python3.5/dist-packages/scrapy/settings/__init__.py", line 292, in setmodule

    module = import_module(module)

  File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module

    return _bootstrap._gcd_import(name[level:], package, level)

  File "<frozen importlib._bootstrap>", line 986, in _gcd_import

  File "<frozen importlib._bootstrap>", line 969, in _find_and_load

  File "<frozen importlib._bootstrap>", line 956, in _find_and_load_unlocked

ImportError: No module named 'douban.settings'

Process finished with exit code 1


写回答 关注

1回答

  • 慕尼黑7825836
    2018-10-13 20:44:29
    已采纳

    在python 代码中加入

    ```
    sys.path.append(os.path.abspath(os.path.join(os.getcwd(), "..")))  # 当前项目路径加入
    ```

    可尝试解决办法:

    配置文件的工作路径   working directory

Python最火爬虫框架Scrapy入门与实践

做为爬虫工程师Python Scrapy主流爬虫框架你必须要会!

67418 学习 · 223 问题

查看课程

相似问题