Jupyter Notebook 설치 및 환경설정

Jupyter Notebook은 데이터 분석, 머신 러닝, 데이터 시각화 등 다양한 데이터 과학 및 프로그래밍 작업을 위한 대화형 개발 환경입니다.
 
비영리 단체 Project Jupyter에서 제작한 제품 중 하나로, 주로 Python을 기반으로 하지만 다양한 프로그래밍 언어를 지원하여 실시간으로 상호 활동적으로 데이터를 확인할 수 있습니다.
iwinv GPU 운영체제 서비스에서는 Jupyter notebook을 통해 작성된 코드를 다양하게 활용할 수 있도록
운영체제 별 Deep Learning 패키지가 포함된 이미지를 바로 사용하도록 지원하고 있습니다.
본 매뉴얼에서는 Jupyter notebook 설치 명령어를 소개합니다.
pip and Python 설치
#  apt-get -y install python3 python3-pip python-dev-is-python3
# python –version
Python 3.10.12
# pip -V
pip 24.0 from /usr/local/lib/python3.10/dist-packages/pip
(python 3.10)
# pip install –upgrade pip
| Collecting pip Downloading pip-24.0-py3-none-any.whl (2.1 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.1/2.1 MB 15.7 MB/s eta 0:00:00 Installing collected packages: pip Attempting uninstall: pip Found existing installation: pip 22.0.2 Not uninstalling pip at /usr/lib/python3/dist-packages, outside environment /usr Can't uninstall 'pip'. No files were found to uninstall. Successfully installed pip-24.0 | 
Jupyter notebook 설치
# pip install jupyter
# jupyter --version
Selected Jupyter core packages...
IPython          : 8.21.0
ipykernel        : 6.29.2
ipywidgets       : 8.1.2
jupyter_client   : 8.6.0
jupyter_core     : 5.7.1
jupyter_server   : 2.12.5
jupyterlab       : 4.1.2
nbclient         : 0.9.0
nbconvert        : 7.16.1
nbformat         : 5.9.2
notebook         : 7.1.0
qtconsole        : 5.5.1
traitlets        : 5.14.1
root 권한에서 작업시에는 아래처럼 메세지가 출력되며 –allow-root 옵션추가
# jupyter notebook
[I 15:55:18.670 NotebookApp] Writing notebook server cookie secret to /root/.local/share/jupyter/runtime/notebook_cookie_secret
[C 15:55:18.848 NotebookApp] Running as root is not recommended. Use –allow-root to bypass.
# jupyter notebook –allow-root

서비스 프로세서가 foreground 형태로 실행되며 세션이 종료되지 않게 backgroud “&” 혹은 nohup 옵션등을 주어 실행한다.
# jupyter notebook –allow-root &
Jupyter 접속
기본포트는 8888 이며 로컬이 아닌 원격에서 웹을 통해 접속하려면 아래와 같은 방법으로 가능합니다.
# netstat -anlp |grep 8888
tcp 0 0 127.0.0.1:8888 0.0.0.0:* LISTEN 19558/python
1. –ip 옵션활용
# ifconfig ens3
ens3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1450
inet 10.1.0.7 netmask 255.255.0.0 broadcast 10.1.255.255
inet6 fe80::f816:3eff:fe47:2c7a prefixlen 64 scopeid 0x20
ether fa:16:3e:47:2c:7a txqueuelen 1000 (Ethernet)
RX packets 27858 bytes 150481517 (150.4 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 16641 bytes 2275966 (2.2 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
# jupyter notebook –allow-root –ip 10.1.0.7 &

# netstat -anlp |grep 8888
tcp 0 0 10.1.0.7:8888 0.0.0.0:* LISTEN 19747/python 
2. 환경설정 config 파일 수정
# jupyter notebook –allow-root –generate-config
Writing default config to: /root/.jupyter/jupyter_notebook_config.py
# vim /root/.jupyter/jupyter_notebook_config.py
| …………………………………… ## The IP address the notebook server will listen on. c.NotebookApp.ip = ‘10.1.0.7’ …………………………………… | 
# jupyter notebook –allow-root –config /root/.jupyter/jupyter_notebook_config.py &

원격에서 접속할수 있는 환경설정은 마무리 되며, 
다음은 웹 브라우저를 통해 접근하시기 바랍니다. 
http://<서버아이피주소>:8888
Password or token 창에는 Jupyter 서버를 실행시킬때 나오는 token 값을 넣어서 진행하시기 바랍니다.

토큰을 입력하고 접근하면 아래와 같은 창이 확인되며, 
환경설정파일을 통해 서비스를 구동시켰다면 jupyter_notebook_config.py 등이 Files 목록에 올라온 모습을 확인하실 수 있습니다. 

python3 추가
– python 3.x = pip3
– python 2.7 = pip
# apt install python3-pip python3-dev
# python3 –version
Python 3.6.9
# pip3 install –upgrade pip
# pip3 install virtualenv
# pip install jupyter

부팅시 자동실행을 위해 service 등록
jupyter.service 파일생성
# vim /etc/systemd/system/jupyter.service
| [Unit] [Service]  [Install] | 
# systemctl daemon-reload
# systemctl enable jupyter.service
# systemctl start jupyter.service
# systemctl status jupyter.service

# jupyter-notebook –h
usage: jupyter-notebook [-h] [–log-level NOTEBOOKAPP.LOG_LEVEL]
                                     [–config NOTEBOOKAPP.CONFIG_FILE]
                                     [–ip NOTEBOOKAPP.IP] [–port NOTEBOOKAPP.PORT]
                                     [–port-retries NOTEBOOKAPP.PORT_RETRIES]
                                     [–transport KERNELMANAGER.TRANSPORT]
                                     [–keyfile NOTEBOOKAPP.KEYFILE]
                                     [–certfile NOTEBOOKAPP.CERTFILE]
                                     [–client-ca NOTEBOOKAPP.CLIENT_CA]
                                     [–notebook-dir NOTEBOOKAPP.NOTEBOOK_DIR]
                                     [–browser NOTEBOOKAPP.BROWSER]
                                     [–pylab [NOTEBOOKAPP.PYLAB]]
                                     [–gateway-url GATEWAYCLIENT.URL] [–debug]
                                     [–generate-config] [-y] [–no-browser] [–no-mathjax]
                                     [–allow-root] [–script] [–no-script]
optional arguments:
   -h, –help show this help message and exit
   --log-level NOTEBOOKAPP.LOG_LEVEL
   --config NOTEBOOKAPP.CONFIG_FILE
   --ip NOTEBOOKAPP.IP
   --port NOTEBOOKAPP.PORT
   --port-retries NOTEBOOKAPP.PORT_RETRIES
   --transport KERNELMANAGER.TRANSPORT
   --keyfile NOTEBOOKAPP.KEYFILE
   --certfile NOTEBOOKAPP.CERTFILE
   –client-ca NOTEBOOKAPP.CLIENT_CA
   –notebook-dir NOTEBOOKAPP.NOTEBOOK_DIR
   –browser NOTEBOOKAPP.BROWSER
   –pylab [NOTEBOOKAPP.PYLAB]
   –gateway-url GATEWAYCLIENT.URL
   –debug
   –generate-config
   -y, –y
   –no-browser
   –no-mathjax
   –allow-root
   –script
   –no-script