linux定時任務python找不到模組問題解決

隱士2018發表於2018-09-07

先說結論:以後在涉及到定時任務,指定python的環境路徑。

shell中python路徑問題

定時任務預設的python路徑為系統自帶

寫一個python程式sys_path.py

import sys

print(sys.path)

放入shell指令碼sys_path.sh

python ./sys_path.py

執行sh指令碼

sh sys_path.sh 

[`/data0/qinyk/test`, `/data0/anaconda3/lib/python36.zip`, `/data0/anaconda3/lib/python3.6`, 

`/data0/anaconda3/lib/python3.6/lib-dynload`, 

`/data0/anaconda3/lib/python3.6/site-packages`, 

`/data0/anaconda3/lib/python3.6/site-packages/PyHive-0.3.0-py3.6.egg`, 

`/data0/anaconda3/lib/python3.6/site-packages/xgboost-0.71-py3.6.egg`]

定時任務crontab -e 並儲存日誌

* * * * * sh sys_path.sh >sys_path.log 2>&1

cat sys_path.log

[`/data0/qinyk/test`, `/usr/lib64/python26.zip`, `/usr/lib64/python2.6`, 

`/usr/lib64/python2.6/plat-linux2`, `/usr/lib64/python2.6/lib-tk`, `/usr/lib64/python2.6/lib-old`, 

`/usr/lib64/python2.6/lib-dynload`, `/usr/lib64/python2.6/site-packages`, 

`/usr/lib64/python2.6/site-packages/gtk-2.0`, `/usr/lib/python2.6/site-packages`]


相關文章