問(wèn)題描述
我想讓一個(gè) cron 作業(yè)使用已經(jīng)存在的名為 my_env 的 anaconda python 環(huán)境執(zhí)行 python 腳本.我唯一能想到的就是讓 cron 作業(yè)運(yùn)行一個(gè)名為 my_script.bash
的腳本,該腳本反過(guò)來(lái)激活 env,然后運(yùn)行 ??python 腳本.
I want to have a cron job execute a python script using an already existing anaconda python environment called my_env. The only thing I can think to do is have the cron job run a script called my_script.bash
which in turn activates the env and then runs the python script.
#!/bin/bash
source activate my_env
python ~/my_project/main.py
嘗試從命令行執(zhí)行此腳本不起作用:
Trying to execute this script from the command lines doesn't work:
$ sh scripts/my_script.bash
scripts/my_script.bash: 9: scripts/my_script.bash: source: not found
我需要做些什么來(lái)確保正確的環(huán)境被激活.可以像我 5 歲一樣向我解釋.
What do I need to do to make sure the proper environment is activated. Its ok to explain it to me like I'm 5.
推薦答案
不要調(diào)用 sh
而是調(diào)用 bash
.source
是一個(gè) bash 命令.
Don't call sh
but bash
. source
is a bash command.
- sh scripts/my_script.bash
+ bash scripts/my_script.bash
或者只是
chmod +x scripts/my_script.bash
./scripts/my_script.bash
自從你添加了 bash shebang.
since you added the bash shebang.
這篇關(guān)于使用 anaconda 環(huán)境運(yùn)行 crontab 作業(yè)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!