

miniconda 를 설치하고나서 가상 환경을 생성하고 activate 하는 과정에서 다음과 같이 에러 메시지가 나왔다.
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
See 'conda init --help' for more information and options.
IMPORTANT: You may need to close and restart your shell after running 'conda init'.
에러 내용을 살펴보면 명령어를 찾을 수 없다는 메시지로 보인다.
이 내용에 대해서 찾아보니 아래의 stackoverflow 에서 다음과 같이 명령어를 실행해주면 된다고 해서 해보았다.
CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'
I'm trying to create a virtual environment using conda on Google Colaboratory. However, I can't activate with the following error. CommandNotFoundError: Your shell has not been properly configu...
stackoverflow.com
댓글에서는 conda git repository 의 issue 에서 해당 내용을 확인할 수 있다고 했다.
https://github.com/conda/conda/issues/7980
Can't execute `conda activate` from bash script · Issue #7980 · conda/conda
Current Behavior Trying to use conda activate my_env does not work inside a bash script. The workaround is to use source activate my_env but this shouldn't be necessary. Steps to Reproduce Write a ...
github.com
자세한 원인에 대해서는 아직 이해가 부족하지만 내용을 간단하게 확인해보니 conda 명령어를 실행하기위한 스크립트를 활성해주어야 하는데 기본적으로 설정이 되어있지 않아 발생하는 문제인 것 같다.
그래서 아래와 같이 conda 명령어를 실행하기 위한 스크립트를 활성화 해줘서 사용할 수 있게 해준다.
source ~/anaconda3/etc/profile.d/conda.sh
conda activate my_env
이렇게 conda.sh 스크립트를 활성화해주니 정상적으로 activate 되었다.
conda.sh 스크립트의 내부를 살펴보면 conda 명령어를 실행하기 위한 스크립트로 보이는데 자세한 동작 방식은 더 살펴봐야할 것 같다.
참고로 현재 기본 환경이 어떤 path 로 잡혀있는지 확인하려면 아래의 명령어를 실행하면 알 수 있다.
conda info | grep -i 'base environment'