Crontab问题与python脚本 [英] Crontab issues with python script

查看:201
本文介绍了Crontab问题与python脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个完全从命令行运行的脚本:

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

完美无瑕地运行脚本。

然后来自在crontab中(已成功用于另一个没有本地导入问题的脚本)我无法让脚本运行。

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没有工作:

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.

推荐答案

我通过创建解决了这个问题。包装器shell脚本。丑陋的是我每次都在导出python路径,但它确实有效。

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

这篇关于Crontab问题与python脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆