2016-10-18 4 views
0

私はjiraモジュール+便利なダンディーロジックを使って私の仕事の一部を行う、すてきな自動化スクリプトを書いた。また、Pythonの呼び出しなしでフルパスでうまく走っに動作します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*** 

:経由して完全にコマンドラインから実行します

[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/binに/のenv pythonのそれを切り替える:私はちょうど私のPYTHONPATHを明示的に宣言して実行するために私のcronジョブを必要とする状態、いくつかの回避策を見てきました

[[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の実行コマンドが見えない理由ですモジュールを見つけることができますが、私は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 

誰でもcronジョブがモジュールを見つけることができない、または唯一の「修正」本当に手動でPYTHONPATHを指定されている理由に任意の洞察力を持っている:私は手動でのcrontabに指定したのと同じcommantを実行することによって、これを確認しましたか?

答えて

1

おそらく明示的にjira_updater.pyでjiraのlibパスを追加する必要があります。

# added code below before import jira 
# append path where jira lib located, for example in /usr/bin/lib 
import sys 
sys.path.append('/usr/bin/lib') 

# if yout don't know where jira located, use code below to get jira path first 
# then put the path found into code sys.path.append above 
import imp;imp.find_module('jira') 
+0

これは完璧に機能しました。私のpythonpathも気に入らなかったので、ありがとうございました! – bubthegreat

関連する問題