Skip to content
Helen Burns edited this page Aug 19, 2018 · 5 revisions

Jupyter Notebooks

What is it?

There a load of useful tutorials online Here

Basically, write your python script as if it were a notebook through a web browser. You can type in directly latex and HTML code to put pictures and equations in. It will convert itself into a python script or .tex file for you! It's really great to share stuff with people that aren't that familiar with python - simply upload your notebook to the nbviewer and share it!

Launching a local notebook is as simple as:

jupyter notebook 

you might want to add

c.IPKernelApp.pylab = 'inline' 

to ~/.ipython/profile_default/ipython_notebook_config.py this will allow plots to show on the screen

http://localhost:8888/

I prefer to setup up to run remotely as its much faster!

Setting up

*Please use the anaconda setup using setup command or if on your own machine, read the Anaconda file in this repository *

  1. Install some extensions
    conda install nb_conda
    pip insall nbbrowserpdf
  1. open ipython through the terminal if you are migrating from ipython notebooks skip this
    ipython
    from IPython.lib import passwd
    passwd()

It will ask you for a password - the nocs system has trouble with symbols Just number and letters and it will work fine! It will output a key

  1. Copy this key if you are migrating from ipython notebooks skip this

Ctrl+Z will suspend this process and take you back to the terminal

  1. Create a profile for a computer e.g. theia if you are migrating from ipython notebooks skip this
    ipython profile create nbtheia
    cd ~/.ipython/profile_nbtheia
  1. now edit the ipython_notebook_config.py if you are migrating from ipython notebooks skip this add or uncomment the following lines:
    c = get_config()

    # Kernel config
    c.IPKernelApp.pylab = 'inline'  # if you want plotting support always

    # Notebook config
    c.NotebookApp.ip = '139.166.240.35' or 'theia.noc.soton.ac.uk 
 
    #Find from ifconfig command of hostname.noc.soton.ac.uk (must specify)

    c.NotebookApp.open_browser = False # If true will launch Firefox through 
                                   # X server (slow!)
    c.NotebookApp.password = u'[Paste your key here]'
    # It is a good idea to put it on a known, fixed port
    c.NotebookApp.port = 9999

If that key is no longer in your clipboard type:

    fg

to resume the ipython session and recopy it else just exit the session now. Create a directory in your home dir for your notebooks e.g.

    mkdir notebooks
    cd notebooks
  1. now let's start the server:
    screen -S nbserver
    jupyter notebook --config='../../.ipython/profile_theia/ipython_notebook_config.py' 

This will start a screen session and launch the server

  1. On your own web browser go to

http://139.166.240.187:9999/ (The IP address and port number)

or

theia.noc.soton.ac.uk:9999

type in your password and start a new notebook.

Some of mine are readable to all so take a look for examples in ~hb1g13/Python/notebooks Now detach the screen so you can close the terminal window

Ctrl+A+D 
  • will detach the screen so you can exit while the process still runs*

If you want to reattach the screen

    screen -r nbserver

I'm super lazy so I've set up aliases in my .cshrc nbtheia etc to start the server and then I've bookmarked the IP addresses.

OPEN SSL

This will allow you to set up a certificate for the ipython notebook server Download latest here

Extract and cd into enclosing directory and run the following commands to build your own OpenSSL

To build:

./config --prefix=/noc/users/$USER --openssldir=/noc/users/$USER/openssl
make && make install

This will add the openssl executable to your ~/bin dir so should work straight away

You can check with

which openssl

should give you your ~/bin/openssl

Troubleshooting

Kernal randomly dying with following error:

ipython notebook kernel died : cannot connect to X server localhost:20.0

FIX: %matplotlib inline

This is some crazy X forwarding error - I don't know why it's not being picked up in profile config file :s

Clone this wiki locally