0

I struggle with running fully activated conda environment from withing cron.

My current solution is calling a specific python interpreter directly with the absolute path, as suggested in many, many posts before. So my current solution looks like this:

# crontab file

* * * * * /home/user/miniconda2/envs/env_xyz/bin/python my_script.py

This works in terms of finding correct python libraries, but it turns out that cron's shell misses some of the virtual-environment-specific environment variables, that get normally loaded in shell's scope with a standard source activate env_xyz.

Authors of the above links provide a solution based on the official conda docs, but this solution seems to be designed for sharing manually added variables, not the ones that get added automatically by installing python dependecies (in my case gdal's GDAL_DATA).

I also tried adding a SHELL=/bin/bash at the beginning of cron file and using many possible shebang/SHELL combinations, all with the same result...

~

Does anybody know how to achieve a behaviour that would allow me calling source activate env_xyz either from cronfile directly, or eventually from within a bash script wrapper, that would then be called by cron?

I would like a portable solution, that would only require versioning of my environment.yml file, not environment variables as well.

Marjan Moderc
  • 2,747
  • 23
  • 44

0 Answers0