본문 바로가기

Programming/Python

[우분투/ubuntu 20.04] Jupyter Notebook 설치하기 / Conda env Kernel 추가

Jupyter 설치

$ pip install jupyter
Collecting jupyter
  Downloading jupyter-1.0.0-py2.py3-none-any.whl (2.7 kB)
Collecting nbconvert
  Downloading nbconvert-6.1.0-py3-none-any.whl (551 kB)
     |████████████████████████████████| 551 kB 858 kB/s 
Collecting jupyter-console
  Downloading jupyter_console-6.4.0-py3-none-any.whl (22 kB)
Collecting qtconsole
  Downloading qtconsole-5.1.1-py3-none-any.whl (119 kB)
     |████████████████████████████████| 119 kB 2.5 MB/s 
Collecting ipykernel
  Downloading ipykernel-6.0.2-py3-none-any.whl (122 kB)
     |████████████████████████████████| 122 kB 7.9 MB/s 
Collecting notebook
  Downloading notebook-6.4.0-py3-none-any.whl (9.5 MB)
     |████████████████████████████████| 9.5 MB 1.1 MB/s
     ... (생략)
Successfully installed MarkupSafe-2.0.1 (생략)

설치 확인

$ jupyter --version
jupyter core     : 4.7.1
jupyter-notebook : 6.4.0
qtconsole        : 5.1.1
ipython          : 7.25.0
ipykernel        : 6.0.2
jupyter client   : 6.1.12
jupyter lab      : not installed
nbconvert        : 6.1.0
ipywidgets       : 7.6.3
nbformat         : 5.1.3
traitlets        : 5.0.5

실행

$ jupyter notebook

http://localhost:8888/tree 를 접속하면 다음과 같은 화면이 보일 것이다.

Conda env (가상환경) kernel jupyter에 추가하기


jupyter notebook 사용가능 패키지 확인

$ jupyter kernelspec list
Available kernels:
  python3    /home/user/.local/share/jupyter/kernels/python3

처음 패키지 리스트에는 anaconda 는 물론 다른 환경에 대한 path는 저장되어 있지 않다.

따라서, conda 가상환경을 생성하고 그 환경을 등록해주면 된다.

 

conda 가상환경 생성

test 라는 이름의 가상환경 생성 (가상환경 이름은 다른 이름도 가능)

$ conda create -n test

 

ipykernel 설치

$ conda activate test
$ conda install ipykernel

위에서 생성한 가상환경을 실행하고 ipykernel 을 설치하면 된다.

 

가상환경 리스트 확인

$ conda env list
# conda environments:
#
base                     /home/user/anaconda3
test                 *  /home/user/anaconda3/envs/test

 

가상환경 연결

위에서 확인한 가상환경 중에 원하는 것을 jupyter notebook에 연결한다.

밑에 명령어 중에서 --name 은 해당 환경의 원래 이름을 말하고

--display-name 은 해당 커널이 jupyter notebook 에서 보일 이름을 말한다.

$ python -m ipykernel install --user --name test --display-name TEST
Installed kernelspec test in /home/user/.local/share/jupyter/kernels/test

 

확인

$ jupyter kernelspec list
Available kernels:
  test      /home/user/.local/share/jupyter/kernels/test
  python3    /home/user/.local/share/jupyter/kernels/python3

저렇듯 원하는 가상환경이 list 에 나타나면 성공이다.

 

 

반응형