Thoughts, stories and ideas.

Jupyterhub 설치하기

우선 눈물을 닦고 시작하자. 파이썬 3.5.2 버전 설치를 위해 반나절을 풀로 날렸다.
그래도 다행인 것은 어느정도 완성을 향해가고 있다는 것과 블로그에 기록을 하고 있다는 것.

패스트 캠퍼스에서 Node.js와 Python을 수강한 지 1년 되었다.
많은 것을 알려주고, 이 세계의 재미를 알려준 수찬이에게 진심으로 감사의 말을 전한다.

Python 3.5.2 설치하기

Step1. Install Required Package

Use the following command to install prerequisites for Python before installing it.

$ sudo apt-get install build-essential checkinstall
$ sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev

Step2. Download Python 3.5.2

Download Python using following commmand from python official site.
You can also download latest version in place of specified below.

$ cd /usr/src
$ sudo wget https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tgz

Now extract the download package.

$ sudo tar xzf Python-3.5.2.tgz

Step3. Compile Python Source

Use below set of commands to compile python source code on your system using altinstall

$ cd Python-3.5.2
$ sudo ./configure
$ sudo make altinstall

make altinstall is used to prevent replacing the default python binary file /usr/bin/python

Step4. Check the Python Version

Check the latest version installed of python using below command

$ python3.5 -V
Python 3.5.2

Step5. Change alias

// vi ~/.bashrc
$ alias python3=`/usr/local/bin/python3.5`

Jupyterhub 설치

sudo apt-get install npm nodejs-legacy #check prerequisites

sudo npm install -g configurable-http-proxy

# Install packages > dev 3.4버전으로 나옴..
sudo apt-get install python3-pip
sudo pip3 install jupyterhub  

sudo pip3 install --upgrade notebook
// 실행하는 위치에서 쿠키, sqlite파일이 생성됨.
sudo jupyterhub

Jupyterhub 도메인 연결해주기

nginx.conf 파일 수정하기
/etc/nginx/sites-available/default

...
location / {
    proxy_pass https://keun.me:8000;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host $http_host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

location ~* /(user/[^/]*)/(api/kernels/[^/]+/channels|terminals/websocket)/? {
    proxy_pass https://keun.me:8000;

    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    proxy_set_header X-NginX-Proxy true;

    # WebSocket support
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_read_timeout 86400;
}

Jupyter Kernel 셋팅하기

현재 사용할 수 있는 커널 확인하기

$ jupyter kernelspec list

필요한 프로그램 (폴더) 만들고 kernel.json 파일 수정하면 완료

$ cd /usr/local/share/jupyter/kernels/
// kernel.json
{
 "language": "python3.5",
 "display_name": "Python 3.5",
 "argv": [
  "/usr/bin/python3",   // or  /usr/local/bin/python3.5
  "-m",
  "IPython.kernel",    // or ipykernel_launcher
  "-f",
  "{connection_file}"
 ]
}

Reference
다중커널개념 이해하기