scrapy cannot import module while it's in my pythonpath

浪子不回头ぞ 提交于 2019-12-06 15:57:46

You have to tell python your PYTHONPATH:

export PYTHONPATH=/path/to/myProject/

and then run scrapy:

sudo scrapy crawl spiderName 2> error.log

By default, when launching a command with sudo, the normal context is not used, so PYTHONPATH is forgotten. In order to have PYTHONPATH with sudo, follow those steps :

  • add PYTHONPATH to Defaults env_keep += "ENV1 ENV2 ..." in sudoers file
  • remove Defaults !env_reset from sudoers file if present

What's wrong of using "sys.path.append()"? I tried many other ways, and determined that "scrapy" doesn't honor the "$PYTHONPATH" for user defined packages. I suspect it loads the directory after the framework has passed the lookup phase. But I tried the "sys.path.append()", it's working.

Jun

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!