run a crontab job using an anaconda env(使用 anaconda 环境运行 crontab 作业)
问题描述
我想让一个 cron 作业使用已经存在的名为 my_env 的 anaconda python 环境执行 python 脚本.我唯一能想到的就是让 cron 作业运行一个名为 my_script.bash 的脚本,该脚本反过来激活 env,然后运行 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
尝试从命令行执行此脚本不起作用:
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
我需要做些什么来确保正确的环境被激活.可以像我 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.
推荐答案
不要调用 sh 而是调用 bash.source 是一个 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.
这篇关于使用 anaconda 环境运行 crontab 作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 anaconda 环境运行 crontab 作业
基础教程推荐
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
- 尝试制作WhatsApp机器人 2022-01-01
- Discord.py 缺少必需的参数 2022-01-01
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
- 用 Python 编写 Fortran 无格式文件 2022-01-01
- 将 x 轴刻度更改为自定义字符串 2022-01-01
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
