简体   繁体   中英

How can I schedule a python script inside a conda env to run every n minutes?

I have a python script getData.py on my mac which I would like to run once every 10 minutes or so. I am aware of crontab and have tried it before using virtual envs. However I need help on how this can be achieved within a conda env that I do my work with.

Thanks

I have a bash script that I run as if it were regular python whenever I need a specific conda environment.

#!/usr/bin/env bash
source <conda-directory>/etc/profile.d/conda.sh
# Uncomment this line to include .profile for environment variables
# source ~/.profile

conda activate <name-of-env>
python "$@"

Save this to a file and run

chmod +x <filename>

to make it executable.

Now you can run this script instead of python. I called my file conda_python , and saved it in my home directory. To run a python script with this environment do

~/conda_python script.py

This should also work from crontab .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM