Show More
@@ -1,273 +1,375 b'' | |||||
1 | .. _htmlnotebook: |
|
1 | .. _htmlnotebook: | |
2 |
|
2 | |||
3 | ========================= |
|
3 | ========================= | |
4 | An HTML Notebook IPython |
|
4 | An HTML Notebook IPython | |
5 | ========================= |
|
5 | ========================= | |
6 |
|
6 | |||
7 | .. seealso:: |
|
7 | .. seealso:: | |
8 |
|
8 | |||
9 | :ref:`Installation requirements <installnotebook>` for the Notebook. |
|
9 | :ref:`Installation requirements <installnotebook>` for the Notebook. | |
10 |
|
10 | |||
11 | The IPython Notebook consists of two related components: |
|
11 | The IPython Notebook consists of two related components: | |
12 |
|
12 | |||
13 | * An JSON based Notebook document format for recording and distributing |
|
13 | * An JSON based Notebook document format for recording and distributing | |
14 | Python code and rich text. |
|
14 | Python code and rich text. | |
15 | * A web-based user interface for authoring and running notebook documents. |
|
15 | * A web-based user interface for authoring and running notebook documents. | |
16 |
|
16 | |||
17 | The Notebook can be used by starting the Notebook server with the |
|
17 | The Notebook can be used by starting the Notebook server with the | |
18 | command:: |
|
18 | command:: | |
19 |
|
19 | |||
20 | $ ipython notebook |
|
20 | $ ipython notebook | |
21 |
|
21 | |||
22 | Note that by default, the notebook doesn't load pylab, it's just a normal |
|
22 | Note that by default, the notebook doesn't load pylab, it's just a normal | |
23 | IPython session like any other. If you want pylab support, you must use:: |
|
23 | IPython session like any other. If you want pylab support, you must use:: | |
24 |
|
24 | |||
25 | $ ipython notebook --pylab |
|
25 | $ ipython notebook --pylab | |
26 |
|
26 | |||
27 | which will behave similar to the terminal and Qt console versions, using your |
|
27 | which will behave similar to the terminal and Qt console versions, using your | |
28 | default matplotlib backend and providing floating interactive plot windows. If |
|
28 | default matplotlib backend and providing floating interactive plot windows. If | |
29 | you want inline figures, you must manually select the ``inline`` backend:: |
|
29 | you want inline figures, you must manually select the ``inline`` backend:: | |
30 |
|
30 | |||
31 |
$ ipython notebook --pylab |
|
31 | $ ipython notebook --pylab inline | |
32 |
|
32 | |||
33 | This server uses the same ZeroMQ-based two process kernel architecture as |
|
33 | This server uses the same ZeroMQ-based two process kernel architecture as | |
34 | the QT Console as well Tornado for serving HTTP/S requests. Some of the main |
|
34 | the QT Console as well Tornado for serving HTTP/S requests. Some of the main | |
35 | features of the Notebook include: |
|
35 | features of the Notebook include: | |
36 |
|
36 | |||
37 | * Display rich data (png/html/latex/svg) in the browser as a result of |
|
37 | * Display rich data (png/html/latex/svg) in the browser as a result of | |
38 | computations. |
|
38 | computations. | |
39 | * Compose text cells using HTML and Markdown. |
|
39 | * Compose text cells using HTML and Markdown. | |
40 | * Import and export notebook documents in range of formats (.ipynb, .py). |
|
40 | * Import and export notebook documents in range of formats (.ipynb, .py). | |
41 | * In browser syntax highlighting, tab completion and autoindentation. |
|
41 | * In browser syntax highlighting, tab completion and autoindentation. | |
42 | * Inline matplotlib plots that can be stored in Notebook documents and opened |
|
42 | * Inline matplotlib plots that can be stored in Notebook documents and opened | |
43 | later. |
|
43 | later. | |
44 |
|
44 | |||
45 | See :ref:`our installation documentation <install_index>` for directions on |
|
45 | See :ref:`our installation documentation <install_index>` for directions on | |
46 | how to install the notebook and its dependencies. |
|
46 | how to install the notebook and its dependencies. | |
47 |
|
47 | |||
48 | .. note:: |
|
48 | .. note:: | |
49 |
|
49 | |||
50 | You can start more than one notebook server at the same time, if you want to |
|
50 | You can start more than one notebook server at the same time, if you want to | |
51 | work on notebooks in different directories. By default the first notebook |
|
51 | work on notebooks in different directories. By default the first notebook | |
52 | server starts in port 8888, later notebooks search for random ports near |
|
52 | server starts in port 8888, later notebooks search for random ports near | |
53 | that one. You can also manually specify the port with the ``--port`` |
|
53 | that one. You can also manually specify the port with the ``--port`` | |
54 | option. |
|
54 | option. | |
55 |
|
55 | |||
56 |
|
56 | |||
57 | Basic Usage |
|
57 | Basic Usage | |
58 | =========== |
|
58 | =========== | |
59 |
|
59 | |||
60 | The landing page of the notebook server application, which we call the IPython |
|
60 | The landing page of the notebook server application, which we call the IPython | |
61 | Notebook *dashboard*, shows the notebooks currently available in the directory |
|
61 | Notebook *dashboard*, shows the notebooks currently available in the directory | |
62 | in which the application was started, and allows you to create new notebooks. |
|
62 | in which the application was started, and allows you to create new notebooks. | |
63 |
|
63 | |||
64 | A notebook is a combination of two things: |
|
64 | A notebook is a combination of two things: | |
65 |
|
65 | |||
66 | 1. An interactive session connected to an IPython kernel, controlled by a web |
|
66 | 1. An interactive session connected to an IPython kernel, controlled by a web | |
67 |
application that can send input to the console and display many types of |
|
67 | application that can send input to the console and display many types of | |
68 |
(text, graphics, mathematics and more). This is the same kernel used |
|
68 | output (text, graphics, mathematics and more). This is the same kernel used | |
69 |
:ref:`Qt console <qtconsole>`, but in this case the web console sends |
|
69 | by the :ref:`Qt console <qtconsole>`, but in this case the web console sends | |
70 |
persistent cells that you can edit in-place instead of the |
|
70 | input in persistent cells that you can edit in-place instead of the | |
71 | terminal style used by the Qt console. |
|
71 | vertically scrolling terminal style used by the Qt console. | |
72 |
|
72 | |||
73 | 2. A document that can save the inputs and outputs of the session as well as |
|
73 | 2. A document that can save the inputs and outputs of the session as well as | |
74 |
additional text that accompanies the code but is not meant for execution. |
|
74 | additional text that accompanies the code but is not meant for execution. | |
75 |
this way, notebook files serve as a complete computational record of a |
|
75 | In this way, notebook files serve as a complete computational record of a | |
76 |
including explanatory text and mathematics, code and resulting |
|
76 | session including explanatory text and mathematics, code and resulting | |
77 |
documents are internally JSON files and are saved with the |
|
77 | figures. These documents are internally JSON files and are saved with the | |
78 | extension. |
|
78 | ``.ipynb`` extension. | |
79 |
|
79 | |||
80 | If you have ever used the Mathematica or Sage notebooks (the latter is also |
|
80 | If you have ever used the Mathematica or Sage notebooks (the latter is also | |
81 | web-based__) you should feel right at home. If you have not, you should be |
|
81 | web-based__) you should feel right at home. If you have not, you should be | |
82 | able to learn how to use it in just a few minutes. |
|
82 | able to learn how to use it in just a few minutes. | |
83 |
|
83 | |||
84 | .. __: http://sagenb.org |
|
84 | .. __: http://sagenb.org | |
85 |
|
85 | |||
86 |
|
86 | |||
87 | Creating and editing notebooks |
|
87 | Creating and editing notebooks | |
88 | ------------------------------ |
|
88 | ------------------------------ | |
89 |
|
89 | |||
90 | You can create new notebooks from the dashboard with the ``New Notebook`` |
|
90 | You can create new notebooks from the dashboard with the ``New Notebook`` | |
91 | button or open existing ones by clicking on their name. Once in a notebook, |
|
91 | button or open existing ones by clicking on their name. Once in a notebook, | |
92 | your browser tab will reflect the name of that notebook (prefixed with "IPy:"). |
|
92 | your browser tab will reflect the name of that notebook (prefixed with "IPy:"). | |
93 | The URL for that notebook is not meant to be human-readable and is *not* |
|
93 | The URL for that notebook is not meant to be human-readable and is *not* | |
94 | persistent across invocations of the notebook server. |
|
94 | persistent across invocations of the notebook server. | |
95 |
|
95 | |||
96 | You can also drag and drop into the area listing files any python file: it |
|
96 | You can also drag and drop into the area listing files any python file: it | |
97 | will be imported into a notebook with the same name (but ``.ipynb`` extension) |
|
97 | will be imported into a notebook with the same name (but ``.ipynb`` extension) | |
98 | located in the directory where the notebook server was started. This notebook |
|
98 | located in the directory where the notebook server was started. This notebook | |
99 | will consist of a single cell with all the code in the file, which you can |
|
99 | will consist of a single cell with all the code in the file, which you can | |
100 | later manually partition into individual cells for gradual execution, add text |
|
100 | later manually partition into individual cells for gradual execution, add text | |
101 | and graphics, etc. |
|
101 | and graphics, etc. | |
102 |
|
102 | |||
|
103 | ||||
103 | Workflow and limitations |
|
104 | Workflow and limitations | |
104 | ------------------------ |
|
105 | ------------------------ | |
105 |
|
106 | |||
106 | The normal workflow in a notebook is quite similar to a normal IPython session, |
|
107 | The normal workflow in a notebook is quite similar to a normal IPython session, | |
107 | with the difference that you can edit a cell in-place multiple times until you |
|
108 | with the difference that you can edit a cell in-place multiple times until you | |
108 | obtain the desired results rather than having to rerun separate scripts with |
|
109 | obtain the desired results rather than having to rerun separate scripts with | |
109 | the ``%run`` magic (though magics also work in the notebook). Typically |
|
110 | the ``%run`` magic (though magics also work in the notebook). Typically | |
110 | you'll work on a problem in pieces, organizing related pieces into cells and |
|
111 | you'll work on a problem in pieces, organizing related pieces into cells and | |
111 | moving forward as previous parts work correctly. This is much more convenient |
|
112 | moving forward as previous parts work correctly. This is much more convenient | |
112 | for interactive exploration than breaking up a computation into scripts that |
|
113 | for interactive exploration than breaking up a computation into scripts that | |
113 | must be executed together, especially if parts of them take a long time to run |
|
114 | must be executed together, especially if parts of them take a long time to run | |
114 | (In the traditional terminal-based IPython, you can use tricks with namespaces |
|
115 | (In the traditional terminal-based IPython, you can use tricks with namespaces | |
115 | and ``%run -i`` to achieve this capability, but we think the notebook is a more |
|
116 | and ``%run -i`` to achieve this capability, but we think the notebook is a more | |
116 | natural solution for that kind of problem). |
|
117 | natural solution for that kind of problem). | |
117 |
|
118 | |||
118 | The only significant limitation the notebook currently has, compared to the qt |
|
119 | The only significant limitation the notebook currently has, compared to the qt | |
119 | console, is that it can not run any code that expects input from the kernel |
|
120 | console, is that it can not run any code that expects input from the kernel | |
120 | (such as scripts that call :func:`raw_input`). Very importantly, this means |
|
121 | (such as scripts that call :func:`raw_input`). Very importantly, this means | |
121 | that the ``%debug`` magic does *not* work in the notebook! We intend to |
|
122 | that the ``%debug`` magic does *not* work in the notebook! We intend to | |
122 | correct this limitation, but in the meantime, there is a way to debug problems |
|
123 | correct this limitation, but in the meantime, there is a way to debug problems | |
123 | in the notebook: you can attach a Qt console to your existing notebook kernel, |
|
124 | in the notebook: you can attach a Qt console to your existing notebook kernel, | |
124 | and run ``%debug`` from the Qt console. If your notebook is running on a local |
|
125 | and run ``%debug`` from the Qt console. If your notebook is running on a local | |
125 | computer (i.e. if you are accessing it via your localhost address at |
|
126 | computer (i.e. if you are accessing it via your localhost address at | |
126 | 127.0.0.1), you can just type ``%qtconsole`` in the notebook and a Qt console |
|
127 | 127.0.0.1), you can just type ``%qtconsole`` in the notebook and a Qt console | |
127 | will open up connected to that same kernel. |
|
128 | will open up connected to that same kernel. | |
128 |
|
129 | |||
129 | In general, the notebook server prints the full details of how to connect to |
|
130 | In general, the notebook server prints the full details of how to connect to | |
130 | each kernel at the terminal, with lines like:: |
|
131 | each kernel at the terminal, with lines like:: | |
131 |
|
132 | |||
132 | [IPKernelApp] To connect another client to this kernel, use: |
|
133 | [IPKernelApp] To connect another client to this kernel, use: | |
133 | [IPKernelApp] --existing kernel-3bb93edd-6b5a-455c-99c8-3b658f45dde5.json |
|
134 | [IPKernelApp] --existing kernel-3bb93edd-6b5a-455c-99c8-3b658f45dde5.json | |
134 |
|
135 | |||
135 | This is the name of a JSON file that contains all the port and validation |
|
136 | This is the name of a JSON file that contains all the port and validation | |
136 | information necessary to connect to the kernel. You can manually start a |
|
137 | information necessary to connect to the kernel. You can manually start a | |
137 | qt console with:: |
|
138 | qt console with:: | |
138 |
|
139 | |||
139 | ipython qtconsole --existing kernel-3bb93edd-6b5a-455c-99c8-3b658f45dde5.json |
|
140 | ipython qtconsole --existing kernel-3bb93edd-6b5a-455c-99c8-3b658f45dde5.json | |
140 |
|
141 | |||
141 | and if you only have a single kernel running, simply typing:: |
|
142 | and if you only have a single kernel running, simply typing:: | |
142 |
|
143 | |||
143 | ipython qtconsole --existing |
|
144 | ipython qtconsole --existing | |
144 |
|
145 | |||
145 | will automatically find it (it will always find the most recently started |
|
146 | will automatically find it (it will always find the most recently started | |
146 | kernel if there is more than one). You can also request this connection data |
|
147 | kernel if there is more than one). You can also request this connection data | |
147 | by typing ``%connect_info``; this will print the same file information as well |
|
148 | by typing ``%connect_info``; this will print the same file information as well | |
148 | as the content of the JSON data structure it contains. |
|
149 | as the content of the JSON data structure it contains. | |
149 |
|
150 | |||
150 |
|
151 | |||
151 | Text input |
|
152 | Text input | |
152 | ---------- |
|
153 | ---------- | |
153 |
|
154 | |||
154 | In addition to code cells and the output they produce (such as figures), you |
|
155 | In addition to code cells and the output they produce (such as figures), you | |
155 | can also type text not meant for execution. To type text, change the type of a |
|
156 | can also type text not meant for execution. To type text, change the type of a | |
156 | cell from ``Code`` to ``Markdown`` by using the button or the :kbd:`Ctrl-m m` |
|
157 | cell from ``Code`` to ``Markdown`` by using the button or the :kbd:`Ctrl-m m` | |
157 | keybinding (see below). You can then type any text in Markdown_ syntax, as |
|
158 | keybinding (see below). You can then type any text in Markdown_ syntax, as | |
158 | well as mathematical expressions if you use ``$...$`` for inline math or |
|
159 | well as mathematical expressions if you use ``$...$`` for inline math or | |
159 | ``$$...$$`` for displayed math. |
|
160 | ``$$...$$`` for displayed math. | |
160 |
|
161 | |||
161 | Exporting a notebook |
|
162 | ||
162 | -------------------- |
|
163 | Exporting a notebook and importing existing scripts | |
|
164 | --------------------------------------------------- | |||
163 |
|
165 | |||
164 | If you want to provide others with a static HTML or PDF view of your notebook, |
|
166 | If you want to provide others with a static HTML or PDF view of your notebook, | |
165 | use the ``Print`` button. This opens a static view of the document, which you |
|
167 | use the ``Print`` button. This opens a static view of the document, which you | |
166 | can print to PDF using your operating system's facilities, or save to a file |
|
168 | can print to PDF using your operating system's facilities, or save to a file | |
167 | with your web browser's 'Save' option (note that typically, this will create |
|
169 | with your web browser's 'Save' option (note that typically, this will create | |
168 | both an html file *and* a directory called `notebook_name_files` next to it |
|
170 | both an html file *and* a directory called `notebook_name_files` next to it | |
169 | that contains all the necessary style information, so if you intend to share |
|
171 | that contains all the necessary style information, so if you intend to share | |
170 | this, you must send the directory along with the main html file). |
|
172 | this, you must send the directory along with the main html file). | |
171 |
|
173 | |||
172 | The `Download` button lets you save a notebook file to the Download area |
|
174 | The `Download` button lets you save a notebook file to the Download area | |
173 | configured by your web browser (particularly useful if you are running the |
|
175 | configured by your web browser (particularly useful if you are running the | |
174 | notebook server on a remote host and need a file locally). The notebook is |
|
176 | notebook server on a remote host and need a file locally). The notebook is | |
175 | saved by default with the ``.ipynb`` extension and the files contain JSON data |
|
177 | saved by default with the ``.ipynb`` extension and the files contain JSON data | |
176 | that is not meant for human editing or consumption. But you can always export |
|
178 | that is not meant for human editing or consumption. But you can always export | |
177 | the input part of a notebook to a plain python script by choosing Python format |
|
179 | the input part of a notebook to a plain python script by choosing Python format | |
178 | in the `Download` drop list. This removes all output and saves the text cells |
|
180 | in the `Download` drop list. This removes all output and saves the text cells | |
179 | in comment areas. |
|
181 | in comment areas. See ref:`below <notebook_format>` for more details on the | |
|
182 | notebook format. | |||
|
183 | ||||
|
184 | The notebook can also *import* ``.py`` files as notebooks, by dragging and | |||
|
185 | dropping the file into the notebook dashboard file list area. By default, the | |||
|
186 | entire contents of the file will be loaded into a single code cell. But if | |||
|
187 | prior to import, you manually add the ``# <nbformat>2</nbformat>`` marker at | |||
|
188 | the start and then add separators for text/code cells, you can get a cleaner | |||
|
189 | import with the file broken into individual cells. | |||
180 |
|
190 | |||
181 | .. warning:: |
|
191 | .. warning:: | |
182 |
|
192 | |||
183 | While in simple cases you can roundtrip a notebook to Python, edit the |
|
193 | While in simple cases you can roundtrip a notebook to Python, edit the | |
184 |
python file and import it back without loss, this is in |
|
194 | python file and import it back without loss of main content, this is in | |
185 | guaranteed to work at all*. As the notebook format evolves in complexity, |
|
195 | general *not guaranteed to work at all*. First, there is extra metadata | |
186 | there will be attributes of the notebook that will not survive a roundtrip |
|
196 | saved in the notebook that may not be saved to the ``.py`` format. And as | |
187 | through the Python form. You should think of the Python format as a way to |
|
197 | the notebook format evolves in complexity, there will be attributes of the | |
188 | output a script version of a notebook and the import capabilities as a way |
|
198 | notebook that will not survive a roundtrip through the Python form. You | |
189 | to load existing code to get a notebook started. But the Python version is |
|
199 | should think of the Python format as a way to output a script version of a | |
190 | *not* an alternate notebook format. |
|
200 | notebook and the import capabilities as a way to load existing code to get a | |
|
201 | notebook started. But the Python version is *not* an alternate notebook | |||
|
202 | format. | |||
191 |
|
203 | |||
192 |
|
204 | |||
193 | Keyboard use |
|
205 | Keyboard use | |
194 | ------------ |
|
206 | ------------ | |
195 |
|
207 | |||
196 | All actions in the notebook can be achieved with the mouse, but we have also |
|
208 | All actions in the notebook can be achieved with the mouse, but we have also | |
197 | added keyboard shortcuts for the most common ones, so that productive use of |
|
209 | added keyboard shortcuts for the most common ones, so that productive use of | |
198 | the notebook can be achieved with minimal mouse intervention. The main |
|
210 | the notebook can be achieved with minimal mouse intervention. The main | |
199 | key bindings you need to remember are: |
|
211 | key bindings you need to remember are: | |
200 |
|
212 | |||
201 | * :kbd:`Shift-Enter`: execute the current cell (similar to the Qt console), |
|
213 | * :kbd:`Shift-Enter`: execute the current cell (similar to the Qt console), | |
202 | show output (if any) and create a new cell below. Note that in the notebook, |
|
214 | show output (if any) and create a new cell below. Note that in the notebook, | |
203 | simply using :kbd:`Enter` *never* forces execution, it simply inserts a new |
|
215 | simply using :kbd:`Enter` *never* forces execution, it simply inserts a new | |
204 | line in the current cell. Therefore, in the notebook you must always use |
|
216 | line in the current cell. Therefore, in the notebook you must always use | |
205 | :kbd:`Shift-Enter` to get execution (or use the mouse and click on the ``Run |
|
217 | :kbd:`Shift-Enter` to get execution (or use the mouse and click on the ``Run | |
206 | Selected`` button). |
|
218 | Selected`` button). | |
207 |
|
219 | |||
208 | * :kbd:`Ctrl-Enter`: execute the current cell in "terminal mode", where any |
|
220 | * :kbd:`Ctrl-Enter`: execute the current cell in "terminal mode", where any | |
209 | output is shown but the cursor stays in the current cell, whose input |
|
221 | output is shown but the cursor stays in the current cell, whose input | |
210 | area is flushed empty. This is convenient to do quick in-place experiments |
|
222 | area is flushed empty. This is convenient to do quick in-place experiments | |
211 | or query things like filesystem content without creating additional cells you |
|
223 | or query things like filesystem content without creating additional cells you | |
212 | may not want saved in your notebook. |
|
224 | may not want saved in your notebook. | |
213 |
|
225 | |||
214 | * :kbd:`Ctrl-m`: this is the prefix for all other keybindings, which consist |
|
226 | * :kbd:`Ctrl-m`: this is the prefix for all other keybindings, which consist | |
215 | of an additional single letter. Type :kbd:`Ctrl-m h` (that is, the sole |
|
227 | of an additional single letter. Type :kbd:`Ctrl-m h` (that is, the sole | |
216 | letter :kbd:`h` after :kbd:`Ctrl-m`) and IPython will show you the remaining |
|
228 | letter :kbd:`h` after :kbd:`Ctrl-m`) and IPython will show you the remaining | |
217 | available keybindings. |
|
229 | available keybindings. | |
218 |
|
230 | |||
|
231 | ||||
|
232 | .. _notebook_security: | |||
|
233 | ||||
219 | Security |
|
234 | Security | |
220 | ======== |
|
235 | ======== | |
221 |
|
236 | |||
222 | You can protect your notebook server with a simple single-password by |
|
237 | You can protect your notebook server with a simple single-password by | |
223 | setting the :attr:`NotebookApp.password` configurable. You can prepare a |
|
238 | setting the :attr:`NotebookApp.password` configurable. You can prepare a | |
224 | hashed password using the function :func:`IPython.lib.security.passwd`: |
|
239 | hashed password using the function :func:`IPython.lib.security.passwd`: | |
225 |
|
240 | |||
226 | .. sourcecode:: ipython |
|
241 | .. sourcecode:: ipython | |
227 |
|
242 | |||
228 | In [1]: from IPython.lib import passwd |
|
243 | In [1]: from IPython.lib import passwd | |
229 | In [2]: passwd() |
|
244 | In [2]: passwd() | |
230 | Enter password: |
|
245 | Enter password: | |
231 | Verify password: |
|
246 | Verify password: | |
232 | Out[2]: 'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed' |
|
247 | Out[2]: 'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed' | |
233 |
|
248 | |||
234 | .. note:: |
|
249 | .. note:: | |
235 |
|
250 | |||
236 | :func:`~IPython.lib.security.passwd` can also take the password as a string |
|
251 | :func:`~IPython.lib.security.passwd` can also take the password as a string | |
237 | argument. **Do not** pass it as an argument inside an IPython session, as it |
|
252 | argument. **Do not** pass it as an argument inside an IPython session, as it | |
238 | will be saved in your input history. |
|
253 | will be saved in your input history. | |
239 |
|
254 | |||
240 | You can then add this to your :file:`ipython_notebook_config.py`, e.g.:: |
|
255 | You can then add this to your :file:`ipython_notebook_config.py`, e.g.:: | |
241 |
|
256 | |||
242 | # Password to use for web authentication |
|
257 | # Password to use for web authentication | |
243 | c.NotebookApp.password = u'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed' |
|
258 | c.NotebookApp.password = u'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed' | |
244 |
|
259 | |||
245 | When using a password, it is a good idea to also use SSL, so that your password |
|
260 | When using a password, it is a good idea to also use SSL, so that your password | |
246 |
is not sent |
|
261 | is not sent unencripted by your browser. You can start the notebook to | |
247 |
protocol mode using a self-signed certificate by |
|
262 | communicate via a secure protocol mode using a self-signed certificate by | |
|
263 | typing:: | |||
248 |
|
264 | |||
249 | $ ipython notebook --certfile=mycert.pem |
|
265 | $ ipython notebook --certfile=mycert.pem | |
250 |
|
266 | |||
251 | .. note:: |
|
267 | .. note:: | |
252 |
|
268 | |||
253 |
A self-signed certificate can be generated with openssl. For example |
|
269 | A self-signed certificate can be generated with openssl. For example, the | |
|
270 | following command will create a certificate valid for 365 days with both | |||
|
271 | the key and certificate data written to the same file:: | |||
254 |
|
272 | |||
255 | $ openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mycert.pem -out mycert.pem |
|
273 | $ openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mycert.pem -out mycert.pem | |
256 |
|
274 | |||
|
275 | Your browser will warn you of a dangerous certificate because it is | |||
|
276 | self-signed. If you want to have a fully compliant certificate that will not | |||
|
277 | raise warnings, it is possible (but rather involved) to obtain one for free, | |||
|
278 | `as explained in detailed in this tutorial`__. | |||
|
279 | ||||
|
280 | .. __: http://arstechnica.com/security/news/2009/12/how-to-get-set-with-a-secure-sertificate-for-free.ars | |||
|
281 | ||||
|
282 | Keep in mind that when you enable SSL support, you'll need to access the | |||
|
283 | notebook server over ``https://``, not over plain ``http://``. The startup | |||
|
284 | message from the server prints this, but it's easy to overlook and think the | |||
|
285 | server is for some reason non-responsive. | |||
|
286 | ||||
|
287 | ||||
|
288 | Quick Howto: running a public notebook server | |||
|
289 | ============================================= | |||
|
290 | ||||
|
291 | If you want to access your notebook server remotely with just a web browser, | |||
|
292 | here is a quick set of instructions. Start by creating a certificate file and | |||
|
293 | a hashed password as explained above. Then, create a custom profile for the | |||
|
294 | notebook. At the command line, type:: | |||
|
295 | ||||
|
296 | ipython profile create nbserver | |||
|
297 | ||||
|
298 | In the profile directory, edit the file ``ipython_notebook_config.py``. By | |||
|
299 | default the file has all fields commented, the minimum set you need to | |||
|
300 | uncomment and edit is here:: | |||
|
301 | ||||
|
302 | c = get_config() | |||
|
303 | ||||
|
304 | # Kernel config | |||
|
305 | c.IPKernelApp.pylab = 'inline' # if you want plotting support always | |||
|
306 | ||||
|
307 | # Notebook config | |||
|
308 | c.NotebookApp.certfile = u'/absolute/path/to/your/certificate/mycert.pem' | |||
|
309 | c.NotebookApp.ip = '*' | |||
|
310 | c.NotebookApp.open_browser = False | |||
|
311 | c.NotebookApp.password = u'sha1:bcd259ccf...your hashed password here' | |||
|
312 | # It's a good idea to put it on a known, fixed port | |||
|
313 | c.NotebookApp.port = 9999 | |||
|
314 | ||||
|
315 | You can then start the notebook and access it later by pointing your browser to | |||
|
316 | ``https://your.host.com:9999``. | |||
|
317 | ||||
|
318 | .. _notebook_format: | |||
|
319 | ||||
|
320 | The notebook format | |||
|
321 | =================== | |||
|
322 | ||||
|
323 | The notebooks themselves are JSON files with an ``ipynb`` extension, formatted | |||
|
324 | as legibly as possible with minimal extra indentation and cell content broken | |||
|
325 | across lines to make them reasonably friendly to use in version-control | |||
|
326 | workflows. You should be very careful if you ever edit manually this JSON | |||
|
327 | data, as it is extremely easy to corrupt its internal structure and make the | |||
|
328 | file impossible to load. In general, you should consider the notebook as a | |||
|
329 | file meant only to be edited by IPython itself, not for hand-editing. | |||
|
330 | ||||
|
331 | .. note:: | |||
|
332 | ||||
|
333 | Binary data such as figures are directly saved in the JSON file. This | |||
|
334 | provides convenient single-file portability but means the files can be | |||
|
335 | large and diffs of binary data aren't very meaningful. Since the binary | |||
|
336 | blobs are encoded in a single line they only affect one line of the diff | |||
|
337 | output, but they are typically very long lines. You can use the | |||
|
338 | 'ClearAll' button to remove all output from a notebook prior to | |||
|
339 | committing it to version control, if this is a concern. | |||
|
340 | ||||
|
341 | The notebook server can also generate a pure-python version of your notebook, | |||
|
342 | by clicking on the 'Download' button and selecting ``py`` as the format. This | |||
|
343 | file will contain all the code cells from your notebook verbatim, and all text | |||
|
344 | cells prepended with a comment marker. The separation between code and text | |||
|
345 | cells is indicated with special comments and there is a header indicating the | |||
|
346 | format version. All output is stripped out when exporting to python. | |||
|
347 | ||||
|
348 | Here is an example of a simple notebook with one text cell and one code input | |||
|
349 | cell, when exported to python format:: | |||
|
350 | ||||
|
351 | # <nbformat>2</nbformat> | |||
|
352 | ||||
|
353 | # <markdowncell> | |||
|
354 | ||||
|
355 | # A text cell | |||
|
356 | ||||
|
357 | # <codecell> | |||
|
358 | ||||
|
359 | print "hello IPython" | |||
|
360 | ||||
|
361 | ||||
257 | Known Issues |
|
362 | Known Issues | |
258 | ============ |
|
363 | ============ | |
259 |
|
364 | |||
260 | When behind a proxy, especially if your system or browser is set to autodetect |
|
365 | When behind a proxy, especially if your system or browser is set to autodetect | |
261 | the proxy, the html notebook might fail to connect to the server's websockets, |
|
366 | the proxy, the html notebook might fail to connect to the server's websockets, | |
262 | and present you with a warning at startup. In this case, you need to configure |
|
367 | and present you with a warning at startup. In this case, you need to configure | |
263 | your system not to use the proxy for the server's address. |
|
368 | your system not to use the proxy for the server's address. | |
264 |
|
369 | |||
265 | In Firefox, for example, go to the Preferences panel, Advanced section, |
|
370 | In Firefox, for example, go to the Preferences panel, Advanced section, | |
266 | Network tab, click 'Settings...', and add the address of the notebook server |
|
371 | Network tab, click 'Settings...', and add the address of the notebook server | |
267 | to the 'No proxy for' field. |
|
372 | to the 'No proxy for' field. | |
268 |
|
373 | |||
269 | Notebook document format |
|
|||
270 | ======================== |
|
|||
271 |
|
||||
272 |
|
374 | |||
273 | .. _Markdown: http://daringfireball.net/projects/markdown/basics |
|
375 | .. _Markdown: http://daringfireball.net/projects/markdown/basics |
General Comments 0
You need to be logged in to leave comments.
Login now