Issue
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
Solution
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
.
Answered By - Marcel Answer Checked By - Marie Seifert (WPSolving Admin)