Crontab issues with python script

倖福魔咒の 提交于 2019-12-12 04:23:54

问题


I have a script that runs perfectly from command line:

/home/anaconda2/bin/python /project_folder/script.py

I added some details below:

$ echo $PYTHONPATH
:/project_folder/

$ which python
/home/anaconda2/bin/python

Which runs the script perfectly, flawlessly.

Then from within crontab (which has been successful for another script that didn't have local import issues) I can't get the script to run.

Crontab of code that doesn't work:

PYTHONPATH=/project_folder
* * * * * /home/anaconda2/bin/python /project_folder/script.py

Nothing happens. It's killing me and much of my time trying to figure this one out - any help much appreciated.


回答1:


I resolved it via creating a wrapper shell script. Ugly in that i'm exporting the python path each time, but it works.

#!/bin/bash
export PYTHONPATH="${PYTHONPATH}:/project_folder"
source ~/.bash_profile
cd /project_folder && /my/anaconda/location/bin/python /project_folder/cript.py


来源:https://stackoverflow.com/questions/42823059/crontab-issues-with-python-script

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