I would like to run a source file that activates a conda environment and then executes a python script. I have tried the following successfully on my other laptob for another script, but it doesn't work on this one.
Any ideas?
(base) ➜ automate_PDP_IMAP git:(master) ✗ pwd
/home/ludo915/automate_PDP_IMAP
(base) ➜ automate_PDP_IMAP git:(master) ✗ conda info --envs
# conda environments:
#
base * /home/ludo915/anaconda3
automate_PDP_IMAP /home/ludo915/anaconda3/envs/automate_PDP_IMAP
(base) ➜ automate_PDP_IMAP git:(master) ✗ source runscripts.sh
Could not find conda environment: base
You can list all discoverable environments with `conda info --envs`.
Not a conda environment: /home/ludo915/anaconda3/envs/automate_PDP_IMAP
': [Errno 2] No such file or directory/automate_PDP_IMAP/runscripts_IMAP.py
(base) ➜ automate_PDP_IMAP git:(master) ✗ cat runscripts.sh
export PATH="/home/ludo915/anaconda3/bin/:$PATH"
eval "$(conda shell.bash hook)"
conda activate /home/ludo915/anaconda3/envs/automate_PDP_IMAP
python /home/ludo915/automate_PDP_IMAP/runscripts_IMAP.py
(base) ➜ automate_PDP_IMAP git:(master) ✗
CodePudding user response:
Try using conda run
rather than manually activating inside a shell script. Activation is designed for interactive shell sessions; conda run
is for programatic execution within an environment context.
#!/usr/bin/env bash -l
conda run -n automate_PDP_IMAP python /home/ludo915/automate_PDP_IMAP/runscripts_IMAP.py