I'm trying to activate my conda env via a bash script. Even though the script runs fine and my PATH appears to be changed within the script, it's getting reset somehow after the script terminates. I can call source activate test
from the cmd line and it works fine. An example along with output below.
script:
PycharmProjects/test » cat ./example.sh echo "before calling source: $PATH" source activate test echo "after calling source: $PATH"
output:
./example.sh before calling source: /Use rs/me/miniconda3/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin discarding /Users/me/miniconda3/bin from PATH prepending /Users/me/miniconda3/envs/test/bin to PATH after calling source: /Users/me/miniconda3/envs/test/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin`
but if I echo $PATH
after the script finishes, you can see that the $PATH
has not changed (i.e. no /Users/me/miniconda3/envs/test/bin
):
PycharmProjects/test » echo $PATH /Users/me/miniconda3/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin
for anaconda 4 : bashrc and then copy the path into the file and save it after that you activate the changes using source . bashrc. When I type export PATH=~/anaconda3/bin:$PATH into the terminal and then run conda --version it works fine.
To activate your Conda environment, type source activate <yourenvironmentname> . Note that conda activate will not work on Discovery with this version. To install a specific package, type conda install -n <yourenvironmentname> [package] . To deactivate the current, active Conda environment, type conda deactivate .
putting source ~/. bashrc in line 2 (running this should put conda in PATH) putting export PATH="/home/ubuntu/anaconda3/bin:$PATH" in place of line 4.
On more recent versions of conda (4.6+), I have noticed that the following works:
eval "$(conda shell.bash hook)" conda activate <env-name>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With