jupyter 에서 여러 가상환경을 커널로 등록해놓고 사용하면 좋다.
다음 bash 명령어를 등록해놓고 쓰면 편하다.
# 주피터 커널 리스트 보기
# jupyter kernelspec list
# 주피터에 뜨는 커널 지우기
# jupyter kernelspec uninstall yourKernel
add_ipykernel() {
ENV_NAME=$1
echo "[LOG] Conda Activate $ENV_NAME and install ipykernel"
conda activate $ENV_NAME && pip install ipykernel
echo "[LOG] Add ipykernel ENV $ENV_NAME to base env"
python -m ipykernel install --user --name $ENV_NAME --display-name $ENV_NAME
echo "Please check by command: jupyter kernelspec list"
conda deactivate
jupyter kernelspec list
}
이게 잘 등록되어 있는지 확인하려면 다음 명령어로 kernel의 설치 경로를 확인한 후,
(base) ➜ ~ jupyter kernelspec list
Available kernels:
spm /Users/user/Library/Jupyter/kernels/spm
python3 /Users/user/miniforge3/share/jupyter/kernels/python3
kernel.json
파일의 python path를 확인해보거나 jupyter notoobk[또는 lab] 혹은 ipython에서 다음과 같이 python path를 찍어보자.
(base) ➜ ~ ipython
Python 3.10.13 | packaged by conda-forge | (main, Oct 26 2023, 18:09:17) [Clang 16.0.6 ]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.25.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: import sys
In [2]: sys.executable
Out[2]: '/Users/user/miniforge3/bin/python3.10'
In [3]: from platform import python_version
In [4]: python_version()
Out[4]: '3.10.13'
혹시라도, 잘 안되는 부분이 있다면 댓글에 남기면 업데이트 하겠음.