게시물 1,375건
   
Jupyter Notebook 설치, 접속, 환경설정
글쓴이 : 최고관리자 날짜 : 2020-02-26 (수) 16:51 조회 : 1757
글주소 :
                                
Jupyter Notebook 설치 및 접속

수십개의 프로그래밍 언어에서 대화형 컴퓨팅을 위한 공개 소스 소프트웨어, 공개 표준 및 서비스를 개발하기 위해 만들어진 비영리 단체 Project Jupyter에서 만든 Product중 하나입니다. 

머신러닝과 Data Science 분야, 과학분야에서 Python을 손쉽게 쓸수 있도록 만들어진 툴로써 실시간으로 인터렉티브하게 데이터를 보여준다는 장점이 있습니다.

파이선코드를 라인별로 실행하고 그에 따른 챠트, 이미지, 비디오등을 시각적으로 보여주고, 복잡한 공식등을 간결하게 수학책처럼 보여주기도하며 개발IDE에 능숙하지 않은 사람들에게 복잡한 파이썬코드를 코드 블럭별로 실행 및 설명하며 공유할수 있는 기능들이 있습니다. 


iwinv 가상서버
환경 : Ubuntu 18.04 LTS

Pip and python 설치
# apt-get -y install python3 python-pip python-dev

# python --version
Python 2.7.17

# pip --version
pip 9.0.1 from /usr/lib/python2.7/dist-packages (python 2.7)

# pip install --upgrade pip
Collecting pip
  Downloading https://files.pythonhosted.org/packages/54/0c/d01aa759fdc501a58f431eb594a17495f15b88da142ce14b5845662c13f3/pip-20.0.2-py2.py3-none-any.whl (1.4MB)
    100% |████████████████████████████████| 1.4MB 612kB/s 
Installing collected packages: pip
  Found existing installation: pip 9.0.1
    Not uninstalling pip at /usr/lib/python2.7/dist-packages, outside environment /usr
Successfully installed pip-20.0.2


jupyter 설치
# pip install jupyter

# jupyter --version
jupyter core     : 4.6.3
jupyter-notebook : 5.7.8
qtconsole        : 4.6.0
ipython          : 5.9.0
ipykernel        : 4.10.1
jupyter client   : 5.3.4
jupyter lab      : not installed
nbconvert        : 5.6.1
ipywidgets       : 7.5.1
nbformat         : 4.4.0
traitlets        : 4.3.3


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<link>
        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://<IPADDRESS>: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 
 <username> 사용자명 및 경로는 본인의 환경에 맞춰서...
[Unit]
Description=Jupyter Notebook Server 

[Service] 
Type=simple 
PIDFile=/run/jupyter.pid 
User=<username> 
ExecStart=/home/<username>/.local/bin/jupyter-notebook 
WorkingDirectory=/your/working/dir

[Install]
WantedBy=multi-user.target

# 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



이름 패스워드
비밀글 (체크하면 글쓴이만 내용을 확인할 수 있습니다.)
왼쪽의 글자를 입력하세요.
   

 



 
사이트명 : 모지리네 | 대표 : 이경현 | 개인커뮤니티 : 랭키닷컴 운영체제(OS) | 경기도 성남시 분당구 | 전자우편 : mojily골뱅이chonnom.com Copyright ⓒ www.chonnom.com www.kyunghyun.net www.mojily.net. All rights reserved.