0

In the part of my bash script I need to switch to specific conda environment to use package that had been installed specifictly in this environment:

#!/bin/bash
home="$PWD"

# activate VINA 1.2.3
conda activate vina
vina --some_in --some_out
# go back to default environment
conda deactivate

While this works fine simply in the terminal (I am using MacOSX) the sh script executing the same commands produces the following errors:

CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
To initialize your shell, run

    $ conda init <SHELL_NAME>

Currently supported shells are:
  - bash
  - fish
  - tcsh
  - xonsh
  - zsh
  - powershell

I've tried to use

conda init bash && conda deactivate

which works fine in the terminal but did not solve the problem in the sh script How I could properly switch between different conda environemnts in the SH script ?

Hot JAMS
  • 173
  • 5
  • 1
    souring this file at the beginning of the script should do the trick: `source $(conda info --base)/etc/profile.d/conda.sh` – cel Dec 08 '21 at 20:32
  • 1
    See https://stackoverflow.com/q/59224591/570918. You'd probably be fine simply changing the shebang to `#!/usr/bin/bash -l`. That is, Conda shell commands (like `conda activate`) are loaded in the `.bashrc`, but if you don't run bash in login mode, it won't source it. – merv Dec 08 '21 at 21:20

0 Answers0