Environment on server

Login to my server:

ssh xx306@login.student.eecs.qmul.ac.uk -A

Installations

Download Anoconda

wget https://repo.anaconda.com/Anaconda2-2019.10-Linux-x86_64.sh

Note: anoconda version xxx see Anaconda installer archive

Install Anoconda

bash Anaconda2-2019.10-Linux-x86_64.sh

Source bash file

source ~/.bashrc

Install Jupyter

conda install jupyter notebook

Configure Jupyter

(base) -bash-4.2$ jupyter notebook --generate-config
Overwrite /homes/xx306/.jupyter/jupyter_notebook_config.py with default config? [y/N]y
Writing default config to: /homes/xx306/.jupyter/jupyter_notebook_config.py

set password

(base) -bash-4.2$ python
Python 3.7.4 (default, Aug 13 2019, 20:35:49) 
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from notebook.auth import passwd 
>>> passwd()
Enter password: 
Verify password: 
'sha1:eb021e5e0da0:57be9ff1fe2075e2afc8591cea27c286f75190d0'

copy this key, exit () python, then:

vim /homes/xx306/.jupyter/jupyter_notebook_config.py

modify the following lines:

c.NotebookApp.ip='*' 
#设置访问notebook的ip,*表示所有IP

c.NotebookApp.password = u'sha1:eb021e5e0da0:57be9ff1fe2075e2afc8591cea27c286f75190d0' 
#填写刚刚复制的密钥 

c.NotebookApp.open_browser = False 
# 禁止notebook启动时自动打开浏览器

c.NotebookApp.allow_remote_access = True
#允许远程连接

c.NotebookApp.port =8889 
#指定访问的端口,默认是8888。

Start Jupyter

(base) -bash-4.2$ jupyter notebook --no-browser --port=8889
[I 12:07:23.759 NotebookApp] JupyterLab extension loaded from /homes/xx306/anaconda3/lib/python3.7/site-packages/jupyterlab
[I 12:07:23.759 NotebookApp] JupyterLab application directory is /homes/xx306/anaconda3/share/jupyter/lab
[I 12:07:23.762 NotebookApp] Serving notebooks from local directory: /homes/xx306
[I 12:07:23.762 NotebookApp] The Jupyter Notebook is running at:
[I 12:07:23.762 NotebookApp] http://localhost:8889/?token=1d84255f936647f2f642dbe9f89ac830d6ab9604770f8741
[I 12:07:23.762 NotebookApp]  or http://127.0.0.1:8889/?token=1d84255f936647f2f642dbe9f89ac830d6ab9604770f8741
[I 12:07:23.763 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 12:07:23.808 NotebookApp] 

    To access the notebook, open this file in a browser:
        file:///homes/xx306/.local/share/jupyter/runtime/nbserver-5513-open.html
    Or copy and paste one of these URLs:
        http://localhost:8889/?token=1d84255f936647f2f642dbe9f89ac830d6ab9604770f8741
     or http://127.0.0.1:8889/?token=1d84255f936647f2f642dbe9f89ac830d6ab9604770f8741

open a local Terminal and type in

ssh -N -f -L localhost:8888:localhost:8889 xx306@login.student.eecs.qmul.ac.uk

Now open web browser (google chrome, firefox, …) and type localhost:8888
We can see the Jupyter Application Site.

Then we see on the server terminal

[I 12:10:06.006 NotebookApp] 302 GET / (::1) 1.09ms
...
...
...

Login to Jupyter Notebook with the token shown in the Server Terminal

Change Jupyter Kernel

list current kernels

jupyter kernelspec list

New environment

conda create -n py27 python=2.7.

Activate

source activate py27

Install the kernel

conda install ipykernel

Install Packages

conda install pandas

or do

conda config --append channels conda-forge

before installing with

conda install pandas

Usage Routine

Login to server:

ssh xx306@login.student.eecs.qmul.ac.uk -A
jupyter notebook --no-browser --port=8889

open a local Terminal and type in

ssh -N -f -L localhost:8888:localhost:8889 xx306@login.student.eecs.qmul.ac.uk

Open localhost:8888 on browser and login to the Jypyter Notebook with the randomly generated tocken.

Tips

Jupyter-NoteBook-你应该知道的N个小技巧

Local Environment

similar but without ssh steps