Issue
I came up with the following bash script to export my conda-env
to a file.
run.sh
#!/usr/bin/bash
while [[ $# -gt 0 ]]; do
option=$1
case "$option" in
-e|--export)
conda env export -n myenv | grep -v "^prefix: " > ../setup/env.yaml
shift
;;
esac
done
the line conda env export -n myenv | grep -v "^prefix: " > ../setup/env.yaml
works as expected when executed in command line. But on executing ./run.sh -e
, the env.yaml
looks like,
name: myenv
channels:
- defaults
Seeking help to fix this. Thanks.
Edit: already tried the string and eval
method from the link (https://stephencowchau.medium.com/simple-bash-script-to-export-all-conda-virtual-environments-2e337cd9480), which also yields the same result as my script.
Edit2: This seems to work in Linux machines. But not working in WSL in windows.
Solution
Adding the following lines in the start of script fixed the issue
CONDA_PATH=$(conda info | grep -i 'base environment' | awk '{print $4}')
source $CONDA_PATH/etc/profile.d/conda.sh
Answered By - Revaapriyan Answer Checked By - Gilberto Lyons (WPSolving Admin)