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

Ipython Notebooks

Ipython notebooks are now depricated, please use 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:

ipython 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 *

Offical info steps don't quite work on the NOCS systems but probably will on your own computer.

  1. open ipython through the terminal
    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

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

  1. Create a profile for a computer e.g. theia

    ipython profile create nbtheia cd ~/.ipython/profile_nbtheia

  2. now edit the ipython_notebook_config.py 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 ipython notebook --profile=nbtheia

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.

NB!!!! From outside the uni network you must VPN!

Converting .ipynb to .py or .tex

Go to your folder with your notebook files to make a python script simply type

ipython nbconvert --to python notebook.ipynb

to make a latex document

ipython nbconvert --to latex notebook.ipynb

You will need to add ~hb1g13/bin/pandoc to your path Either copy it over or just add ~hb1g13/bin/ to your path in your .cshrc

setenv PATH "${PATH}:/noc/users/hb1g13/bin"

I store a lot of stuff in there so it is probably best to have your own ~/bin dir and copy over the file and simply add instead

setenv PATH "${PATH}:/noc/users/$USER/bin"

TROUBLESHOOTING

  1. Backends: Trouble with pyside/ matplotlib - you will need to edit:

~/.config/matplotlib/matplotlibrc

If you are using a more complex setup that might not be the right config file you can find out using:

import matplotlib
matplotlib.matplotlib_fname()

Normally I find switching away from Pyside fixes most things!

  1. 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