HOW TO INSTALL IPYTHON FROM SCRATCH ON DEBIAN 7
################################################

Links that I used to get this information and install ipython with:

Installation and uninstallation:
http://www.installion.co.uk/debian/wheezy/main/i/ipython-notebook/install.html
http://www.installion.co.uk/debian/wheezy/main/i/ipython-notebook/uninstall.html

Configuration & General:
http://askubuntu.com/questions/335883/how-to-use-the-newest-ipython-in-ubuntu12-04
http://ipython.org/ipython-doc/rel-1.1.0/interactive/public_server.html
http://nbviewer.ipython.org/github/ipython/ipython-in-depth/blob/master/notebooks/Running%20a%20Secure%20Public%20Notebook.ipynb

Side Note about SSL file types (since we use either a single pem, or crt & key file – i recommend just to get a single pem file which will include the key and crt, thats how below config will instruct you):
http://serverfault.com/questions/9708/what-is-a-pem-file-and-how-does-it-differ-from-other-openssl-generated-key-file

Before Installation
####################

 

NOTE: my sources.list looks like this (so make sure yours has it):

 

Installation
#############

I will show you 2 installation methods, the one that I did and the much much easier one (that you should use)

Method1 – Short – from link
==============================

 

Method2 – Long – the one I did (using pip, thus insures latest version of ipython)
===================================================================

First I wanted to start fresh so I “apt-get removed” everything python related on my system. This in the processes uninstalled GNOME (thats a big warning, I never used gnome so it was okay for me, im a CLI guy that likes console and putty+ssh)

PYTHON MEGA UNINSTALL:

Find every python module and delete it (if you dont have the paste command):

DO THIS:
——–

 

Find every python module and delete it (if you do have the paste command):

OR THIS:
——–

 

THEN AFTER EITHER OF THOSE DO THESE:
————————————-

Fix any dependencies after the uninstall:

 

Confirm “dpkg -l” is now missing everything python related:

This should show every debian package, python should be missing:
dpkg -l | grep python

PYTHON INSTALL:

 

Lets get the latest pip:

 

NOTE: instead you can just do “apt-get install python-pip”

Lets install any dependencies that might come up

 

SUGGESTED MOVE: you can just install all of the possibile dependencies:

 

Now lets install some pip stuff (this installs python modules, just a bunch of .py and .pyc files that go into python folders across the system, and thus you can then “import <module>” in your code)

NOTE: if some fail to install or give errors, try to look for the error that says missing header file (.h file) and find it perhaps using this method: http://www.infotinks.com/debian-missing-file-compiling/ and fix the problem by installing the right module (thats why above I had so many apt-gets, so that we would get every possible program that would be needed to install all of these pip modules no problem)

NOTE: some of these are not needed for ipython like pattern or path.py, I just threw them in for fun. Some are needed like readline and jinja and pyzmq and jinja2 and a few others.

NOTE: installing ipython with pip instead of apt-get ensures latest version of ipython

 

In the end when my ipython worked it looked like this (try to match it, if your having problems):

 

And of course here is my python related debian packages (other important packages are not showing on here like g++ and gcc but they are there)

 

CONFIGURATION
###############

After using installation method1 or method2. Lets setup the module. The setup for our netbook would be:
– available on all interfaces
– ssl (so uses https) so need a cert file (a pem file would be easiest, a chain of crt and key files)
– a password for added security (generated with IPython.lib.passwd

Make Password
==============

Type in:

 

You can launch python or ipython with several executables, I use either the one without the version number or the latest one. You might have python3 and python3.2, I wouldnt use that for this.

After inside a python program type in these commands @ the prompts:

 

The first line imports the passwd module that can make a password for us. On the second line we set our password and we should remember it and note it, and that password gets turned into an encrypted formated and saved into the variable “password”. Then typing “password” without anything will show the value its holding

Make Cert
===========

I like to keep my certs

 

Fill out the information (its important to fill out the server FQDN correctly, type it in as it would appear when your accessing your webserver from far away/remotely):

 

Make the notebook file and configure it
=========================================

cd /

We are going to make a notebook called “nbserver”, this is also called a ‘profile’

 

NOTE: you can probably use the other versions of ipython (which 1.1), ipython2.6, and ipython2.7. Just replace the word “ipython” in the previous version with either “ipython2.6” or “ipython2.7” depending on what you have. I have all 3, if you used the long method of install you will probably get all those too.

NOTE: the location where the notebook was made and the config file went (it should tell you when you make the notebook)

At the top you will see “c = get_config()”, you will add your config in at the top (the rest of the config file is commented out, at least in my case – if its not commented out for you, I would just exit out of vi, copy that config file to ipython_config.py.bak and then edit ipython_config.py again with vi, delete everything in there, so that your config just has the following in it config in it)

So make sure your config file just has this (not includeing the “CONFIG FILE” line and the “====” line below it):

Config File (https+password+every interface, short url)
========================================================

 

Config File (https+password+every interface, short url) – Same config as above without comments
===================================================================

 

Config File (http+password+every interface, long url)
========================================================

Config File(No password+http+every interace, short url)
==========================================================

 

Config File (No password+https+every interace, short url)
==========================================================

 

LAUNCHING IPYTHON
##################

To launch it, just tell ipython to pull up your profile you just configured:

SIDENOTE: I was going to say to enable inline graphix and plots like this:

ipython notebook –profile=nbserver –pylab=inline
HOWEVER we dont need to do that, as our config takes care of that with this line: “c.IPKernelApp.pylab = ‘inline’

Now go to your browser and access it with the appropriate link, if you used my commented config file you will access it like this

From the same machine where you installed it, open a browser:
https://localhost:50000/

From a remote machine:
https://ipython.infotinks.com:50000/

Where “ipython.infotinks.com” is your ip address or your hostname

The use of ipython is now discussion for other articles and your own learning….

To get out of ipython
———————-

Control-C, then press y and enter, might have to do that again, Control-C and then y and enter again.

TIP: Launching Ipython in screen (Can do it with dtach as well, check out my dtach and screen articles)

Article on Screen and detach: LINK

Here is a screen example
————————-

Launching ipython like this will make it so it doesnt use up a shell per say and it will run in the background, thus if you close the shell your ipython wont crash

 

Then you can close out the shell and it will still run (or detach with CONTROL-a and then type “:detach” without the quotes and hit ENTER.)

To see if ipython is running
——————————

Or:

See what tcp ports are being listened to and by what processes ( you should see ipython listening on your port with this ):
netstat -ntlp

NOTE: -n for no hostnames & no port names, just names. -t for TCP, and -l for listening, and -p to give program names. -u for UDP

NOTE: “netstat -nulp” is for udp. To see all tcp and udp listening ports “netstat -ntulp
To start ipython on boot
————————–

In your /etc/rc.local add in the ipython start command line above the “exit 0”. So first edit the file

vi /etc/rc.local

Then add this

NOTE: the above method works on debian if you have sysvinit or systemd. If you have systemd you can utilize another method as well (but then dont use the rc.local script)

http://echorand.me/2013/09/22/managing-ipython-notebook-server-via-systemd-part-i/

https://gist.github.com/amitsaha/6658720

UNINSTALLING IPYTHON
#####################

If you used method1 of install this will go along with it:

Uninstalling just ipython-notebook:
————————————

 

Uninstalling ipythonnotebook and its dependencies:
————————————————–

 

Or:

 

If you want to get rid of your Configs and data as well:
——————————————————–

Or:

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *