所以我寫了一個漂亮的自動化腳本,通過jira模塊+方便的花花公子爲我做了一些工作。它在命令行中通過完美運行:僅適用於crontab作業的ImportError?
[email protected]] ~/Documents/auto_updater > python /Users/me/Documents/auto_updater/jira_updater.py
Missing info starting
checking out: ES-20157
No array outage
Already has sev1_missing_outage label.
***snip***
它也工作得很好,跑了FULLPATH不蟒蛇電話:
[email protected]] ~/Documents/auto_updater > /Users/me/Documents/auto_updater/jira_updater.py
Missing info starting
checking out: ES-20157
No array outage
Already has sev1_missing_outage label.
現在 - 假設它的工作方式生活是美好的,我決定其設置在30個分鐘週期的crontab中,每一次我收到的垃圾郵件的失敗似乎如不能找到JIRA模塊:
From [email protected] Mon Oct 17 19:30:04 2016
Return-Path: <[email protected]>
X-Original-To: me
Delivered-To: [email protected]
Received: by me-mbp (Postfix, from userid 502)
id 514D0203328A; Mon, 17 Oct 2016 19:30:00 -0600 (MDT)
From: [email protected] (Cron Daemon)
To: [email protected]
Subject: Cron <[email protected]> python /Users/me/Documents/auto_updater/jira_updater.py >> /Users/me/Documents/auto_updater/updated_log.txt
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=me>
X-Cron-Env: <USER=me>
X-Cron-Env: <HOME=/Users/me>
Message-Id: <[email protected]>
Date: Mon, 17 Oct 2016 19:30:00 -0600 (MDT)
Traceback (most recent call last):
File "/Users/me/Documents/auto_updater/jira_updater.py", line 3, in <module>
from jira.client import JIRA
ImportError: No module named jira.client
本來我曾與#問題的/ usr/bin/python pa日,所以我把它切換到#的/ usr /斌/包膜蟒蛇:
[[email protected]] ~/Documents/auto_updater > head jira_updater.py
#!/usr/bin/env python
from jira.client import JIRA
import random
# Here's some responses that we can randomize from so it doesn't feel quite so botty.
FIRST_RESPONSES = ['- Do you need help moving this forward?',
'- Can I help you get traction on this?',
我已經看到了一些解決方法該狀態我只需要我的cronjob與我的PYTHONPATH明確地宣告運行,但是,似乎是一個劣質的解決方法,我建立了一個服務器爲我運行這個,所以我寧願通過使事情正常工作來解決它 - 但我無法弄清楚爲什麼cronjob運行命令不能看起來找到該模塊,但我可以以root身份運行它,其語法與crontab中指定的相同。
[email protected]] ~/Documents/auto_updater > crontab -l
*/30 * * * * python /Users/me/Documents/auto_updater/jira_updater.py >> /Users/me/Documents/auto_updater/updated_log.txt
任何人有任何瞭解爲什麼的cronjob無法找到模塊,或者手動指定PYTHONPATH真正唯一的「修復」:我已經通過手動運行在crontab中指定的相同commant驗證了這一點?
工作完美 - 它不喜歡我的pythonpath,所以非常感謝! – bubthegreat