Solution found:
os.popen (or for that matter subprocess.run) start new sub-processes that don't inherit the conda environment
You have to string your various commands together into a single popen or subprocess command. For example:
def run_cameratrap(image_dir: str = '', output_dir: str = '',
json_file: str = '', threshold: str = '',
batch_size: str = ''):
import subprocess
import os
base_dir = os.environ.get("DATADIR")
images = os.path.join(base_dir, image_dir)
output_dir = os.path.join(base_dir, output_dir)
threshold = "--threshold " + threshold
batch_size = "--batch_size " + batch_size
init_cmd = 'eval "$(conda shell.bash hook)";'
activate_cmd = " conda activate wildlife;"
detector_cmd = "run_detector " + images + " " + output_dir + " " + json_file + " " + threshold + " " + batch_size
final_cmd = init_cmd + activate_cmd + detector_cmd
output = subprocess.run(final_cmd, capture_output=True, text=True, shell=True)
return output
-------------------------------------------------------------
Comments about this solution
1. init_cmd has to be as given above. conda init did not work.
We also found that when we were using conda on our compute cluster, users
had to put the same thing in their job scripts because conda init did not work in that situation either.
2. Initially we had the DATADIR environment variable set when the wildlife environment was activated
but since we need it before the string of commands that actually runs conda we moved the
variable into config.yaml in the worker_init section by doing export=DATADIR=/mydirectory
Hopefully someone from Globus sees this information and gets it into the online documentation