-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathipython.txt
245 lines (149 loc) · 4.98 KB
/
ipython.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
IPython
=======
Steven K. Baum
v0.1, 2014-07-14
:doctype: book
:toc:
:icons:
:numbered!:
[preface]
Overview
--------
About Ipython.
Links
-----
Home Page - http://ipython.org/[+http://ipython.org/+]
IPython Notebook -
http://ipython.org/notebook.html[+http://ipython.org/notebook.html+]
Jupyter, the Next Generation of IPython Notebook-
https://github.com/jupyter[+https://github.com/jupyter+]
Installation
------------
IPython
~~~~~~~
Get the development version from:
https://github.com/ipython/ipython[+https://github.com/ipython/ipython+]
Download, compile and install using:
-----
git clone https://github.com/ipython/ipython.git
cd ipython
python2.7 setup.py build
su
python2.7 setup.py install
-----
IPython Notebook
~~~~~~~~~~~~~~~~
Pandoc
^^^^^^
First, install the Haskell platform via:
http://www.haskell.org/platform/[+http://www.haskell.org/platform/+]
Then install +pandoc+ using +cabal+:
-----
cabal update
cabal install pandoc
-----
Using Notebook
--------------
Basic Commands
~~~~~~~~~~~~~~
Starting Notebook
^^^^^^^^^^^^^^^^^
After entering:
-----
ipython notebook
-----
on the command line, you will get a new window or tab
opening that looks like:
image::ipython/ipython-initial.png[link="ipython/ipython-initial.png"]
Creating a New Notebook
^^^^^^^^^^^^^^^^^^^^^^^
Click on the +New Notebook+ tab to obtain another tab/window that looks like:
image::ipython/ipython-notebook-1.png[link="ipython/ipython-notebook-1.png"]
Entering and Running Python Code
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Now enter some code into this in what is called *edit mode*:
image::ipython/ex-01.png[link="ipython/ex-01.png"]
and then click on the +Run Cell+ button:
image::ipython/run_icon.png[link="ipython/run_icon.png"]
to obtain:
image::ipython/ex-02.png[link="ipython/ex-02.png"]
Running System Commands
^^^^^^^^^^^^^^^^^^^^^^^
System commands can be run. The first two are system aliases, and
the third demonstrates how any command line program can be run
using +!+ with string interpolation from Python variables.
image::ipython/ex-system-commands.png[link="ipython/ex-system-commands.png"]
Rich Display System
~~~~~~~~~~~~~~~~~~~
The +display+ function is a general purpose tool for displaying different
representations of objects, i.e. sort of a print command for objects.
A notebook with the following examples is at:
http://nbviewer.ipython.org/github/ipython/ipython/blob/master/examples/Notebook/Display%20System.ipynb[+http://nbviewer.ipython.org/github/ipython/ipython/blob/master/examples/Notebook/Display%20System.ipynb+]
Links to Local Files
^^^^^^^^^^^^^^^^^^^^
Links to local files can be created via the +FileLink+ object, e.g.
-----
from IPython.display import FileLink, FileLinks
-----
If there
is a file named +README.rst+ in the directory from which +ipython notebook+
was invoked, it can be accessed in the following way.
image::ipython/filelink.png[link="ipython/filelink.png"]
Links to External Sites
^^^^^^^^^^^^^^^^^^^^^^^
An entire page from another wite can be embedded into an iframe using
-----
from IPython.display import IFrame
-----
An example that embeds today's Wikipedia page for mobile users is:
image::ipython/ex-wikipedia.png[link="ipython/ex-wikipedia.png"]
HTML Rendering
^^^^^^^^^^^^^^
HTML can be displayed in the notebook by using the +HTML+ class:
-----
from IPython.display import HTML
-----
image::ipython/ex-html-01.png[link="ipython/ex-html-01.png"]
If you are using Pandas, this can be used to allow
+DataFrames+ to be represented as HTML classes.
image::ipython/ex-html-02.png[link="ipython/ex-html-02.png"]
LaTeX Rendering
^^^^^^^^^^^^^^^
Mathematical expressions typeset with LaTeX can be displayed using
the MathJax +Math+ class:
-----
from IPython.display import Math
-----
An example is:
image::ipython/ex-latex-01.png[link="ipython/ex-latex-01.png"]
They can also be displayed using the +Latex+ class:
-----
from IPython.display import Latex
-----
although you have to include the delimiters yourself, which allows
you to use other LaTeX modes such as +eqnarray+.
image::ipython/ex-latex-02.png[link="ipython/ex-latex-02.png"]
LaTeX can also be entered directly using +%%latex+ cell magic.
image::ipython/ex-latex-03.png[link="ipython/ex-latex-03.png"]
Using a Notebook Server on a Remote Machine on a Local Machine
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
https://coderwall.com/p/ohk6cg[+https://coderwall.com/p/ohk6cg+]
Enter the following on the remote machine +barataria+:
-----
/opt/anaconda/bin/ipython notebook --no-browser --port=8889
-----
Create an SSH tunnel on your local machine:
-----
ssh -N -f -L localhost:8888:localhost:8889 [email protected]
-----
Open a browser on your machine and type the following into the address bar:
-----
localhost:8888
-----
and a tab or window will open to the remote notebook server.
To kill the SSH tunnel, search for it via:
-----
ps aux | grep localhost:8889
-----
and kill the process in the usual way.
The server on +barataria can be killed with +ctrl-c ctrl-c+.