My setup is something like this: I have an EC2 machine running Ubuntu, which powers a Django site. I want to be able to launch IPython Notebook on the remote server such that:
- It knows about Django and can import my models properly
- I can just write the code in a web browser on my local machine
- It's secure in that there's not just a stray notebook on the web that anyone can look at
My mom mentioned the Django extension 'shell_plus' the other day, and that turned out to be key to this solution!
(I did this a few days ago and don't remember all the details, I *think* it was this simple.)
- IPython Notebook
- pip install "ipython[notebook]"
- shell_plus via django-extensions
- pip install django-extensions
There are a couple steps that I wrote down for myself (and now you) since they are hard to remember until you've done them many times.
First, I connect to the server through an SSH tunnel. On my local machine, I run
ssh -L 9999:localhost:8888 mycoolserver.com
The second port (the 8888) is the remote port. That needs to be 8888 for IPython Notebook, unless you can convince it to run on a different port. The first port (9999) is the local one, and you can change it if you want.
On the remote server, (in the SSH connection I just made, or a separate one, doesn't matter) I launch IPython Notebook using Django's manage.py and shell_plus, with an extra argument to stop it from trying to launch a browser. I want to use a local browser, not a remote one.
./manage.py shell_plus --notebook --no-browser
Back on my local machine, that 9999 I had in the first command comes in to play. I go to Chrome and visit:
And from there, I can do all the normal IPython Notebook and interactive Django shell things! At the same time!
To stop things, I kill the IPython Notebook by killing the ./manage.py process, and then I kill the SSH connection.