Show More
@@ -1,8 +1,8 b'' | |||
|
1 | 1 | .. _htmlnotebook: |
|
2 | 2 | |
|
3 |
==================== |
|
|
4 | An HTML Notebook IPython | |
|
5 |
==================== |
|
|
3 | ==================== | |
|
4 | The IPython Notebook | |
|
5 | ==================== | |
|
6 | 6 | |
|
7 | 7 | .. seealso:: |
|
8 | 8 | |
@@ -10,37 +10,50 b' An HTML Notebook IPython' | |||
|
10 | 10 | |
|
11 | 11 | The IPython Notebook consists of two related components: |
|
12 | 12 | |
|
13 | * An JSON based Notebook document format for recording and distributing | |
|
14 | Python code and rich text. | |
|
15 | * A web-based user interface for authoring and running notebook documents. | |
|
13 | * A web application for interactive authoring of literate computations, combining explanatory text, mathematics, computations and rich media output. Input and output are stored in persistent cells that may be edited in-place. | |
|
14 | ||
|
15 | * Notebook documents for recording and distributing | |
|
16 | the results. | |
|
17 | ||
|
18 | ||
|
19 | Features of the IPython Notebook web app | |
|
20 | ---------------------------------------- | |
|
21 | ||
|
22 | Some of the main | |
|
23 | features of the IPython Notebook app include: | |
|
24 | ||
|
25 | * Display rich data representations (e.g. HTML / LaTeX / SVG) in the browser as a result of computations. | |
|
26 | * Compose text cells using Markdown and HTML. | |
|
27 | * Include mathematical equations, rendered directly in the browser by MathJax. | |
|
28 | * Import standard Python scripts | |
|
29 | * In-browser editing, syntax highlighting, tab completion and autoindentation. | |
|
30 | * Inline figures rendered by the ``matplotlib`` library with publication quality, in a range of formats (SVG / PDF / PNG). | |
|
31 | ||
|
32 | If you have ever used the Mathematica or SAGE notebooks (the latter is also | |
|
33 | web-based__) you should feel right at home. If you have not, you will be | |
|
34 | able to learn how to use it in just a few minutes. | |
|
35 | ||
|
36 | .. __: http://sagenb.org | |
|
37 | ||
|
16 | 38 | |
|
17 | The Notebook can be used by starting the Notebook server with the | |
|
18 | command:: | |
|
19 | 39 | |
|
20 | $ ipython notebook | |
|
21 | 40 | |
|
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:: | |
|
24 | ||
|
25 | $ ipython notebook --pylab | |
|
26 | 41 | |
|
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 | |
|
29 | you want inline figures, you must manually select the ``inline`` backend:: | |
|
42 | Notebook documents | |
|
43 | ------------------ | |
|
30 | 44 | |
|
31 | $ ipython notebook --pylab inline | |
|
45 | Notebook documents, or *notebooks*, are files which record all computations carried out and the results obtained in a literate way, including inputs, outputs, toegether with descriptive text and mathematics. | |
|
32 | 46 | |
|
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 | |
|
35 | features of the Notebook include: | |
|
47 | They are plain text files, which are thus easy to share with colleagues and place under version control. But, by using the | |
|
48 | JSON format, they can record all aspects of the computation, including embedding rich media output. | |
|
49 | The standard file extension for notebook documents is ``.ipynb``. | |
|
50 | ||
|
51 | Notebooks may easily be exported to a range of static formats, including HTML (for example, for blog posts), PDF and slide shows. | |
|
52 | Furthermore, any publicly | |
|
53 | available notebook may be shared via the `IPython Notebook Viewer | |
|
54 | <http://nbviewer.ipython.org>`_ service, which will provide it as a static web | |
|
55 | page. The results may thus be shared without having to install anything. | |
|
36 | 56 | |
|
37 | * Display rich data (png/html/latex/svg) in the browser as a result of | |
|
38 | computations. | |
|
39 | * Compose text cells using HTML and Markdown. | |
|
40 | * Import and export notebook documents in range of formats (.ipynb, .py). | |
|
41 | * In browser syntax highlighting, tab completion and autoindentation. | |
|
42 | * Inline matplotlib plots that can be stored in Notebook documents and opened | |
|
43 | later. | |
|
44 | 57 | |
|
45 | 58 | See :ref:`our installation documentation <install_index>` for directions on |
|
46 | 59 | how to install the notebook and its dependencies. |
@@ -49,93 +62,74 b' how to install the notebook and its dependencies.' | |||
|
49 | 62 | |
|
50 | 63 | You can start more than one notebook server at the same time, if you want to |
|
51 | 64 | work on notebooks in different directories. By default the first notebook |
|
52 |
server starts |
|
|
65 | server starts on port 8888, and later notebook servers search for ports near | |
|
53 | 66 | that one. You can also manually specify the port with the ``--port`` |
|
54 | 67 | option. |
|
55 | 68 | |
|
56 | 69 | |
|
57 | Basic Usage | |
|
58 | =========== | |
|
70 | Starting the IPython Notebook web app | |
|
71 | ===================================== | |
|
59 | 72 | |
|
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 | |
|
62 | in which the application was started, and allows you to create new notebooks. | |
|
73 | The Notebook web app can be started with the command:: | |
|
63 | 74 | |
|
64 | A notebook is a combination of two things: | |
|
75 | $ ipython notebook | |
|
65 | 76 | |
|
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 | |
|
68 | output (text, graphics, mathematics and more). This is the same kernel used | |
|
69 | by the :ref:`Qt console <qtconsole>`, but in this case the web console sends | |
|
70 | input in persistent cells that you can edit in-place instead of the | |
|
71 | vertically scrolling terminal style used by the Qt console. | |
|
77 | The landing page of the notebook server application, the *dashboard*, shows the notebooks currently available in the working directory (the directory from which the notebook was started). | |
|
78 | You can create new notebooks from the dashboard with the ``New Notebook`` | |
|
79 | button, or open existing ones by clicking on their name. | |
|
72 | 80 | |
|
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. | |
|
75 | In this way, notebook files serve as a complete computational record of a | |
|
76 | session including explanatory text and mathematics, code and resulting | |
|
77 | figures. These documents are internally JSON files and are saved with the | |
|
78 | ``.ipynb`` extension. | |
|
79 | 81 | |
|
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 | |
|
82 | able to learn how to use it in just a few minutes. | |
|
82 | You can also drag and drop into the area listing files any ``.py`` | |
|
83 | file: it will be imported into a notebook with the same name (but | |
|
84 | ``.ipynb`` extension), located in the working directory. This notebook will consist of a single cell with all the code in the file, which you can later manually partition into individual cells for gradual execution, and add text | |
|
85 | and graphics, etc. | |
|
86 | Alternatively, | |
|
87 | prior to import, you can manually add ``# <nbformat>2</nbformat>`` | |
|
88 | markers at the start and then add separators for text/code cells, to get a cleaner import with the file already broken into individual cells. | |
|
83 | 89 | |
|
84 | .. __: http://sagenb.org | |
|
85 | 90 | |
|
91 | The IPython Notebook web app is based on a server-client structure. | |
|
92 | This server uses a two-process kernel architecture based on ZeroMQ, as well as Tornado for serving HTTP requests. Other clients may connect to the same underlying IPython kernel. | |
|
86 | 93 | |
|
87 | Creating and editing notebooks | |
|
88 | ------------------------------ | |
|
89 | 94 | |
|
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, | |
|
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* | |
|
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 | |
|
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 | |
|
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 | |
|
101 | and graphics, etc. | |
|
96 | Basic workflow | |
|
97 | ------------------------ | |
|
102 | 98 | |
|
103 | 99 | |
|
104 | Workflow and limitations | |
|
105 | ------------------------ | |
|
100 | Once in a notebook, your browser tab will reflect the name of that notebook (prefixed with "IPy"). | |
|
101 | The URL for that notebook is currently not meant to be human-readable and is not persistent across invocations of the notebook server; however, this will change soon. | |
|
102 | ||
|
103 | The normal workflow in a notebook is quite similar to a normal IPython | |
|
104 | session, with the difference that you can edit a cell in-place multiple | |
|
105 | times until you obtain the desired resultsj, rather than having to | |
|
106 | rerun separate scripts with the ``%run`` magic (though magics also work | |
|
107 | in the notebook). Typically you'll work on a problem in pieces, | |
|
108 | organizing related pieces into cells and moving forward as previous | |
|
109 | parts work correctly. This is much more convenient for interactive exploration than breaking up a computation into scripts that must be | |
|
110 | executed together, especially if parts of them take a long time to run | |
|
111 | ||
|
112 | The only significant limitation that the notebook currently has, compared to the qt console, is that it can not run any code that | |
|
113 | expects input from the kernel (such as scripts that call | |
|
114 | :func:`raw_input`). Very importantly, this means that the ``%debug`` | |
|
115 | magic does *not* currently work in the notebook! This limitation will | |
|
116 | be overcome in the future, but in the meantime, there is a way to debug problems in the notebook: you can attach a Qt console to your existing notebook kernel, and run ``%debug`` from the Qt console. | |
|
117 | If your notebook is running on a local | |
|
118 | computer (i.e. if you are accessing it via your localhost address at ``127.0.0.1``), you can just type ``%qtconsole`` in the notebook and a Qt console will open up, connected to that same kernel. | |
|
119 | ||
|
120 | ||
|
121 | Connecting to an existing kernel | |
|
122 | --------------------------------- | |
|
106 | 123 | |
|
107 | The normal workflow in a notebook is quite similar to a normal IPython session, | |
|
108 | with the difference that you can edit a cell in-place multiple times until you | |
|
109 | obtain the desired results rather than having to rerun separate scripts with | |
|
110 | the ``%run`` magic (though magics also work in the notebook). Typically | |
|
111 | you'll work on a problem in pieces, organizing related pieces into cells and | |
|
112 | moving forward as previous parts work correctly. This is much more convenient | |
|
113 | for interactive exploration than breaking up a computation into scripts that | |
|
114 | must be executed together, especially if parts of them take a long time to run | |
|
115 | (In the traditional terminal-based IPython, you can use tricks with namespaces | |
|
116 | and ``%run -i`` to achieve this capability, but we think the notebook is a more | |
|
117 | natural solution for that kind of problem). | |
|
118 | ||
|
119 | The only significant limitation the notebook currently has, compared to the qt | |
|
120 | console, is that it can not run any code that expects input from the kernel | |
|
121 | (such as scripts that call :func:`raw_input`). Very importantly, this means | |
|
122 | that the ``%debug`` magic does *not* work in the notebook! We intend to | |
|
123 | correct this limitation, but in the meantime, there is a way to debug problems | |
|
124 | in the notebook: you can attach a Qt console to your existing notebook kernel, | |
|
125 | and run ``%debug`` from the Qt console. If your notebook is running on a local | |
|
126 | computer (i.e. if you are accessing it via your localhost address at | |
|
127 | 127.0.0.1), you can just type ``%qtconsole`` in the notebook and a Qt console | |
|
128 | will open up connected to that same kernel. | |
|
129 | ||
|
130 | In general, the notebook server prints the full details of how to connect to | |
|
131 | each kernel at the terminal, with lines like:: | |
|
124 | The notebook server always prints to the terminal the full details of | |
|
125 | how to connect to each kernel, with lines like:: | |
|
132 | 126 | |
|
133 | 127 | [IPKernelApp] To connect another client to this kernel, use: |
|
134 | 128 | [IPKernelApp] --existing kernel-3bb93edd-6b5a-455c-99c8-3b658f45dde5.json |
|
135 | 129 | |
|
136 |
This is the name of a JSON file that contains all the port and |
|
|
137 |
information necessary to connect to the kernel. You can |
|
|
138 |
|
|
|
130 | This is the name of a JSON file that contains all the port and | |
|
131 | validation information necessary to connect to the kernel. You can | |
|
132 | manually start a Qt console with:: | |
|
139 | 133 | |
|
140 | 134 | ipython qtconsole --existing kernel-3bb93edd-6b5a-455c-99c8-3b658f45dde5.json |
|
141 | 135 | |
@@ -143,10 +137,10 b' and if you only have a single kernel running, simply typing::' | |||
|
143 | 137 | |
|
144 | 138 | ipython qtconsole --existing |
|
145 | 139 | |
|
146 |
will automatically find it (it will always find the most recently |
|
|
147 |
kernel if there is more than one). You can also request this |
|
|
148 |
by typing ``%connect_info``; this will print the same |
|
|
149 | as the content of the JSON data structure it contains. | |
|
140 | will automatically find it (it will always find the most recently | |
|
141 | started kernel if there is more than one). You can also request this | |
|
142 | connection data by typing ``%connect_info``; this will print the same | |
|
143 | file information as well as the content of the JSON data structure it contains. | |
|
150 | 144 | |
|
151 | 145 | |
|
152 | 146 | Text input |
@@ -181,12 +175,6 b' in the `Download` drop list. This removes all output and saves the text cells' | |||
|
181 | 175 | in comment areas. See ref:`below <notebook_format>` for more details on the |
|
182 | 176 | notebook format. |
|
183 | 177 | |
|
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. | |
|
190 | 178 | |
|
191 | 179 | .. warning:: |
|
192 | 180 |
General Comments 0
You need to be logged in to leave comments.
Login now