jupyter notebook (was ipython notbook)


4 posts
by Rich107 » Mon Dec 28, 2015 10:56 pm
Hi all,

I have been at this a while now and Google has failed me...

My goal is to have a Jupiter notebook server running on the pi which I can just ssh into. Now I have installed Jupiter and it will run manually however, I wish to use rc.local or crontab to run it at boot so I can schedule a reboot at night and not have to start up the server each time I want to use it but I have had no joy.

These are my failed crontab attempts:
@reboot /usr/local/bin/jupyter notebook &
@reboot "/usr/local/bin/jupyter notebook" &

I have a raspberry pi 2 running Raspbian

Any help would be appreciated
Posts: 7
Joined: Thu Oct 16, 2014 10:35 am
by Rich107 » Mon Dec 28, 2015 11:29 pm
Well that's annoying... a few mins after I post this I find an answer

I have added this to my /etc/rc.local file above exit 0:

(nohup /usr/local/bin/jupyter-notebook > /var/log/jupyter1-boot.log 2>&1) &

my error was missing out the - between jupyter and notebook. Solution found here: https://github.com/jupyter/notebook/issues/448

Hope this helps others as I think jupyter notebook rather a handy way to code on a headless pi.
Posts: 7
Joined: Thu Oct 16, 2014 10:35 am
by starly » Thu Dec 31, 2015 8:01 am
Hi, I found your post when searching for ipython. Just wanted to ask.. if ipython through canopy (enthought) is supported for raspberry pi? The reason I ask is from what I understand the benefit of installing ipython through enthought/canopy is that it comes with many other libraries pre-packaged in a stable format. I haven't tried this myself yet but if you have some insight on this would love to hear your thoughts. Also, was curious if you installed any libraries for ipython/python on your own for raspeberry pi and if they worked ok. Last but not least, could you point me to some reading material or elaborate a little bit more on the 'headless' setup you have for ipython on pi and then I guess your main data files on your laptop/other machine? I'm just starting to explore raspberry pi and would love to learn more about your approach.
Thanks!
Posts: 1
Joined: Thu Dec 31, 2015 7:52 am
by Rich107 » Mon Jan 04, 2016 1:57 pm
Hi Starly,

Unfortunately I have never used Enthought so don't have much to say on it. But I have a few tips on installing packages which might help you out and how I use Jupyter Notebook as part of my headless setup.

Installing Librarys:
I tend to follow the instructions form the library's reliant website for using pip to install it.
You can install pip using:

Code: Select all
sudo apt-get update

Code: Select all
sudo apt-get install python-pip


When installed this way it can be a slightly out of date version. To make sure it is the latest version of pip use:
Code: Select all
sudo pip install -U pip


Once it is updated to the latest version you can install librarys which should look something like this to install jupyter for example:
Code: Select all
sudo pip install jupyter


My headless method:
When I log in with ssh I tend to log in with certain ports automatically forwarded off the back of that connection so web-servers or databases ran locally on the raspberry pi can be seen by the computer I am using to access the Raspberry Pi. This allows me to run Jupiter Notebook on the Raspberry Pi and access the webpage it creates remotely.

Notebook is great as I make a lot of mistakes when coding. It has auto complete and allows you to run your code in blocks so you can test your code in segments to help you debug it and build it up gradually. It returns outputs such as print() and errors directly under the block you are running. The code you write with it is running on the pi itself so you know that when it works its working on the pi. Finally it is useful to download and upload files using the Jupyter Dashboard to and from your pi.

Tunneling:
Setting up the Local forwarding for the ports is different for Mac and Ubuntu vs Windows.

On a mac or Ubuntu:
I use the .ssh/config to create shortcuts, open a terminal:
sudo nano .ssh/config

Then you can copy in this and tweak for your settings:
Code: Select all
Host Screen1
    User pi
    Port 22
    HostName 192.168.1.15
    LocalForward 8888 127.0.0.1:8888
    LocalForward 3306 127.0.0.1:3306


ctrl + x then ctrl + y to save and exit.

Host - This is the nickname for the connection setting as you can have several in this file
Port - Is optional if using the default 22
HostName - Is the IP address in this case a local one but it can be a web address such as a duckdns.org a free dns service.
LocalForward - For simplicity just copy these and change 3306 to the port you want.

To connect to you pi just use ssh:
Code: Select all
ssh Screen1

(or whatever you put after Host)

On Windows I use Putty:
Download from: http://www.chiark.greenend.org.uk/~sgta ... nload.html
I downloaded Putty.exe

There are plenty of guides on how to connect via putty so i will briefly mention the ports:
Click the +ssh tab on the left
Then tunnels
Use this window to configure your ports for example:
Source Port: 8888
Destination: 127.0.0.1:8888
Click add
Rinse and repeat for any other ports if necessary

At the top left click on session
Under saved sessions give it a nickname
Click Save
Click Open
Login as normal.

Using either of these methods will mean the machine you are login onto your pi with (Client) has those ports as if they were local. Once you have Jupiter notebook installed you can do the following:
Run jupyter notebook:
Code: Select all
sudo jupyter notebook


Go to a browser on the Client machine and enter into the url bar:
127.0.0.1:8888

You should then be presented with the Jupyter Dashboard.
Posts: 7
Joined: Thu Oct 16, 2014 10:35 am