Austin Godber
@godber
DesertPy - 3/26/2014
sudo apt-get update && sudo apt-get upgradebrew install ipythonpip install ipythonIt's not so much about IPython as the other things in your toolkit.
Just type:
ipythonAn enhanced command line with these features
+------------------+----------------------------+
| Python Help      | Magic                      |
| Sytem Aliases    | Dynamic Object Information |
| Tab Completion   | Searchable History         |
| Logging          | Session save and restore   |
| System Commands  | Colorized output           |
| Input Caching    | Output Caching             |
+------------------+----------------------------+Knowing these two is sufficient
Describes IPython features with hints.
(%q TAB - for the lazy)
% (or not)? to see docs on a magic - %reset?execute a file:
%run file.py
%run reloads from the disk every time so its good for iterative development.
open foo.py in your editor and execute it on exit:
%edit foo.py
save IPython lines 9 through 12 into file2.py:
%save file2.py 9-12
print out all variables in interactive namespace:
%who
print more!!!!!
%whos
reset interactive namespace, clears variables:
%reset
toggle the need for % in front of magics:
%automagic
show all of the many more magics:
%magic
!!ls
!ls *.py
py_files = !ls *.pya = range(10)
g = !ping google.com -c 5
g
g. TAB
g.grep('ttl')
who
whosIn [1]: def sq(n):
   ...:     return n*n
   ...:
In [2]: sq(5)
Out[2]: 25
In [4]: %save sq.py 1In a new session
In [1]: %run sq.py
In [2]: sq(6)
Out[2]: 36from IPython.display import Image
Image(filename="austin-relax.png")
Yes, thats what I look like when I relax.
We are going from this ...
Image(filename="ipython-cli.png")
to this ...
Image(filename="ipython-notebook.png")
Just type
ipython notebookor
ipython notebook --ip=0.0.0.0 --port=9999 -no-browser# This is a cell
a = 'This '
print a + "is cell output"
This is cell output
code - in the previous example, executes python codemarkdown - is a markup language that gets converted to HTMLheader - HTML Header cellsraw - Raw Text too!%%%%capture - capture cell contents%%writefile - write cell contents to file%%ruby
puts "Hi #{RUBY_VERSION}"
Hi 1.9.3
%%bash
echo "hi from $BASH"
hi from /bin/bash
To get inline graphics (shown as output in the browser) start each notebook with:
%matplotlib inline
or when you start your notebook server start it with the option:
--pylab=inline
Visit the following URL to play along:
http://ipynb.desertpy.com
(active only during this presentation)
import numpy as np
import matplotlib.pyplot as plt
# don't forget the
# %matplotlib inline
x = np.linspace(0, 10, 20)
y = x ** 2
plt.plot(x,y)
[<matplotlib.lines.Line2D at 0x3acda10>]
# from http://scipy-lectures.github.io/packages/scikit-image/
import skimage
from skimage import io
import os
filename = os.path.join(skimage.data_dir, 'camera.png')
camera = skimage.io.imread(filename)
camera.view()
# image is displayed
(3 * camera).view()
The demo server has my Pandas presentation checked out into it. You can use cd, ls and %load or %run to run my examples.
cd pandas_examples/
ls
%load
# or
%runvim and use %run to load it into notebooknbconvert subcommand of ipython (it had been a separate tool but was merged).ipython nbconvert mynotebook.ipynb --to html --template basicipython nbconvert mynotebook.ipynb --to latexipython nbconvert mynotebook.ipynb --to latex --post PDFipython nbconvert mynotebook.ipynb --to rstipython nbconvert IPython_Presentation.ipynb --to slidesMy notebook runs on my desktop but I'm not home?
Make it accessible using ngrok!
Generate a password hash:
>>> from IPython.lib import passwd
>>> passwd()
Enter password:
Verify password:
'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed'Generate the notebook config file
$ ipython profile create nbserverPlace the bash in the config file
# Password to use for web authentication
c = get_config()
c.NotebookApp.password =
u'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed'Launch the Notebook Server:
ipython notebook --profile==nbserverServe it publicly with ngrok:
~/bin/ngrok -proto='https' 8888
# now running on https://e082589425.ngrok.comAustin Godber
@godber
http://desertpy.com/presentations