Cron wont import pandas module to execute python script. ```ImportError: No module named pandas```
Cron wont import pandas module to execute python script. ```ImportError: No module named pandas```
我使用的是 xubuntu 18.01
我有一个 python 程序可以抓取天气数据并将文件保存为 csv。在我使用 chmod +x weatherdata
.
授予它权限后,它完美地 运行 在终端中执行命令 weatherdata
我希望使用 cron 每 2 周 运行。但是我设置后没有任何反应
我正在使用 NANO cron 编辑器
我已经尝试设置 cronjob PATH 变量,SHELL=/bin/bash/。 P 把/bin/bash放在命令前面...都无济于事....
# crontab -e
SHELL=/bin/bash
MAILTO= mygmail@gmail.com (removed my actual email for privacy)
PATH=/home/luke/bin/
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
34 * * * * /bin/bash /home/luke/bin/weatherdata
我预计 weatherdata
python 文件会在整点后 34 分钟每小时执行一次。
没有任何反应,我没有收到电子邮件或任何东西。
编辑:
我把top改成了
SHELL=/bin/bash
#MAILTO=mygmail@gmail.com (commented it out)
PATH=/home/luke/bin/:/usr/sbin:/usr/bin:/sbin:/bin
我在 运行ning 之后得到了什么:
15 * * * * /bin/bash /home/luke/bin/weatherdata > /tmp/weatherlog 2>&1
正如评论中所建议的那样。
Traceback (most recent call last):
File "/home/luke/Documents/Duka/Master_River_Levels_LOOP.py", line 9, in <module>
import pandas as pd
ImportError: No module named pandas
Traceback (most recent call last):
File "/home/luke/Documents/Duka/Temp_Mean_Weather_loop.py", line 9, in <module>
import pandas as pd
ImportError: No module named pandas
我需要为 python 脚本导入一些模块到 运行,第一个是 panadas。
crontab -e 作业看起来不错。
为什么不直接使用:
34 * * * * /home/luke/bin/weatherdata
或者设置一个 sh 文件...例如。
myfile.sh
#!/usr/local/env bash
/home/luke/bin/weatherdata
然后crontab -e读取
34 * * * * /home/luke/myfile.sh
除非您的系统管理员阻止它,否则 Cron 可以实现梦想。
正如@thatotherguy 所说,问题出在我的路径上。
1) 我在终端 运行 echo $PATH
回来了:
/home/luke/anaconda3/bin:/home/luke/anaconda3/condabin:/home/luke/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
2) 我复制并粘贴上面的路径来替换: PATH=/home/luke/bin/:/usr/sbin:/usr/bin:/sbin:/bin
和
PATH=/home/luke/anaconda3/bin:/home/luke/anaconda3/condabin:/home/luke/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
3) 我把PATH=/
改成了PATH=$PATH:/
现在 cronjob 执行得很好。
我使用的是 xubuntu 18.01
我有一个 python 程序可以抓取天气数据并将文件保存为 csv。在我使用 chmod +x weatherdata
.
weatherdata
我希望使用 cron 每 2 周 运行。但是我设置后没有任何反应
我正在使用 NANO cron 编辑器
我已经尝试设置 cronjob PATH 变量,SHELL=/bin/bash/。 P 把/bin/bash放在命令前面...都无济于事....
# crontab -e
SHELL=/bin/bash
MAILTO= mygmail@gmail.com (removed my actual email for privacy)
PATH=/home/luke/bin/
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
34 * * * * /bin/bash /home/luke/bin/weatherdata
我预计 weatherdata
python 文件会在整点后 34 分钟每小时执行一次。
没有任何反应,我没有收到电子邮件或任何东西。
编辑:
我把top改成了
SHELL=/bin/bash
#MAILTO=mygmail@gmail.com (commented it out)
PATH=/home/luke/bin/:/usr/sbin:/usr/bin:/sbin:/bin
我在 运行ning 之后得到了什么:
15 * * * * /bin/bash /home/luke/bin/weatherdata > /tmp/weatherlog 2>&1
正如评论中所建议的那样。
Traceback (most recent call last):
File "/home/luke/Documents/Duka/Master_River_Levels_LOOP.py", line 9, in <module>
import pandas as pd
ImportError: No module named pandas
Traceback (most recent call last):
File "/home/luke/Documents/Duka/Temp_Mean_Weather_loop.py", line 9, in <module>
import pandas as pd
ImportError: No module named pandas
我需要为 python 脚本导入一些模块到 运行,第一个是 panadas。
crontab -e 作业看起来不错。
为什么不直接使用:
34 * * * * /home/luke/bin/weatherdata
或者设置一个 sh 文件...例如。 myfile.sh
#!/usr/local/env bash
/home/luke/bin/weatherdata
然后crontab -e读取
34 * * * * /home/luke/myfile.sh
除非您的系统管理员阻止它,否则 Cron 可以实现梦想。
正如@thatotherguy 所说,问题出在我的路径上。
1) 我在终端 运行 echo $PATH
回来了:
/home/luke/anaconda3/bin:/home/luke/anaconda3/condabin:/home/luke/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
2) 我复制并粘贴上面的路径来替换: PATH=/home/luke/bin/:/usr/sbin:/usr/bin:/sbin:/bin
和
PATH=/home/luke/anaconda3/bin:/home/luke/anaconda3/condabin:/home/luke/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
3) 我把PATH=/
改成了PATH=$PATH:/
现在 cronjob 执行得很好。