##// END OF EJS Templates
Proofreading finished up to connecting to existing kernel
David P. Sanders -
Show More
@@ -279,7 +279,7 b' Cell magics'
279 279
280 280 * ``%%file filename``:
281 281 Writes the contents of the cell to the file ``filename``.
282 **Caution**: The file is ovewritten!
282 **Caution**: The file is over-written!
283 283
284 284 * ``%%R``:
285 285 Execute the contents of the cell using the R language.
@@ -305,7 +305,7 b' It will import at the top level `numpy` as `np`, `pyplot` as `plt`, `matplotlib`'
305 305
306 306 When the default ``%matplotlib`` or ``%pylab`` magics are used, the output of a plotting command is captured in a *separate* window. An alternative is to use::
307 307
308 ``%matplotlib inline``
308 %matplotlib inline
309 309
310 310 or ``%pylab inline``.
311 311
@@ -316,19 +316,17 b' Converting notebooks to other formats'
316 316 -------------------------------------
317 317 Newly added in the 1.0 release of IPython is the ``nbconvert`` tool, which allows you to convert an ``.ipynb`` notebook document file into another static format.
318 318
319 Currently, only a command line tool is provided; at present, this functionality is not available for direct exports from within the Notebook app. The syntax is::
319 Currently, only a command line tool is provided; in the future, it will also be possible to export from within the Notebook app. The command line syntax is::
320 320
321 321 $ ipython nbconvert --format=FORMAT notebook.ipynb
322 322
323 which will convert the IPython document file `notebook.ipynb` into the output format specified by the `FORMAT` string.
323 This will convert the IPython document file `notebook.ipynb` into the output format specified by the ``FORMAT`` string.
324 324
325 325 The default output format is HTML, for which the `--format`` modifier is not required::
326 326
327 327 $ ipython nbconvert notebook.ipynb
328 328
329 Otherwise, the following `FORMAT`
330
331 where ``FORMAT`` is the desired export format. The currently export format options available are the following:
329 The currently supported export formats are the following:
332 330
333 331 * HTML:
334 332
@@ -344,10 +342,10 b' where ``FORMAT`` is the desired export format. The currently export format optio'
344 342 * PDF:
345 343
346 344 - ``sphinx_howto``:
347 The format for Sphinx HOWTOs; similar to `article` in LaTeX
345 The format for Sphinx HOWTOs; similar to an ``article`` in LaTeX
348 346
349 347 - ``sphinx_manual``:
350 The format for Sphinx manuals; similar to `book` in LaTeX
348 The format for Sphinx manuals; similar to a `book`` in LaTeX
351 349
352 350 - ``latex``:
353 351 LaTeX article
@@ -355,37 +353,37 b' where ``FORMAT`` is the desired export format. The currently export format optio'
355 353 * Markup:
356 354
357 355 - ``rst``:
358 reStructuredText
356 reStructuredText markup
359 357
360 358 - ``markdown``:
361 Markdown
359 Markdown markup
362 360
363 361 * Python:
364 362
365 Produces a standard ``.py`` script, with the non-Python code commented out.
363 Comments out all the non-Python code to produce a standard Python ``.py`` script with just the code content.
366 364
367 The output files are currently placed in a new subdirectory called
368 ``nbconvert_build``.
365 The files output by `nbconvert` are currently placed in a new subdirectory called ``nbconvert_build``.
369 366
370 The PDF options produce a root LaTeX `.tex` file with the same name as the notebook, as well as individual files for each figure, and `.text` files with textual output from running code cells; all of these files are located together in the `nbconvert_build` subdirectory.
367 The PDF options produce a root LaTeX ``.tex`` file with the same name as the notebook, as well as individual files for each figure, and `.text` files with textual output from running code cells; all of these files are located together in the ``nbconvert_build`` subdirectory.
371 368
372 To actually produce the final PDF file, simply run::
369 To actually produce the final PDF file, change into the ``nbconvert_build`` directory and run the following command::
373 370
374 371 $ pdflatex notebook
375 372
376 which produces `notebook.pdf`, also inside the `nbconvert_build` subdirectory.
373 This requires a local installation of LaTeX on your machine.
374 It produes the output PDF file ``notebook.pdf``, also inside the
375 ``nbconvert_build`` subdirectory.
377 376
378 Alternatively, the output may be piped to standard output `stdout` with::
377 Alternatively, the output may be piped to standard output, ``stdout``, with::
379 378
380 379 $ ipython nbconvert mynotebook.ipynb --stdout
381 380
382 Multiple notebooks can be specified at the command line in a couple of
383 different ways::
381 Multiple notebooks can be specified at the command line::
384 382
385 383 $ ipython nbconvert notebook*.ipynb
386 384 $ ipython nbconvert notebook1.ipynb notebook2.ipynb
387 385
388 or via a list in a configuration file, containing::
386 or via a list in a configuration file, say ``mycfg.py``, containing the text::
389 387
390 388 c.NbConvertApp.notebooks = ["notebook1.ipynb", "notebook2.ipynb"]
391 389
@@ -394,15 +392,15 b' and using the command::'
394 392 > ipython nbconvert --config mycfg.py
395 393
396 394
397 Configuration
398 -------------
395 Configuring the IPython Notebook
396 --------------------------------
399 397 The IPython Notebook can be run with a variety of command line arguments.
400 398 To see a list of available options enter::
401 399
402 400 $ ipython notebook --help
403 401
404 402 Defaults for these options can also be set by creating a file named
405 `ipython_notebook_config.py`` in your IPython *profile folder*. The profile folder is a subfolder of your IPython directory; to find out where it is located, run::
403 ``ipython_notebook_config.py`` in your IPython *profile folder*. The profile folder is a subfolder of your IPython directory; to find out where it is located, run::
406 404
407 405 $ ipython locate
408 406
@@ -417,13 +415,11 b' To create a new set of default configuration files, with lots of information on '
417 415
418 416 Extracting standard Python files from notebooks
419 417 -----------------------------------------------
418 ``.ipynb`` notebook document files are plain text files which store a representation in JSON format of the contents of a notebook space. As such, it is not a valid ``.py`` Python script, and so can be neither ``import``ed in Python, nor executed as a standard Python script.
420 419
421 The native format of the notebook, a file with a ``.ipynb`` `extension, is a
422 JSON container of all the input and output of the notebook, and therefore not
423 valid Python by itself. This means that by default, you cannot directly
424 import a notebook from Python, nor execute it as a normal python script.
420 To extract just the Python code from within a notebook document, one option is to use ``ipython nbconvert``, as described above.
425 421
426 But if you want to be able to use notebooks also as regular Python files, you can start the notebook server with::
422 An alternative is to run the IPython Notebook, specifying that whenever it saves an ``.ipynb`` notebook document, at the same time it should save the corresponding standard ``.py`` script. To do so, you can execute the following command::
427 423
428 424 ipython notebook --script
429 425
@@ -431,19 +427,14 b' or you can set this option permanently in your configuration file with::'
431 427
432 428 c.NotebookManager.save_script=True
433 429
434 This will instruct the notebook server to save the ``.py`` export of each
435 notebook, in addition to the ``.ipynb``, at every save. These are standard
436 ``.py`` files, and so they can be ``%run``, imported from regular IPython
437 sessions or other notebooks, or executed at the command line. Since we export
438 the raw code you have typed, for these files to be importable from other code,
439 you will have to avoid using syntax such as ``%magic``s and other IPython-specific extensions to the language.
430 The result is that standard ``.py`` files are also now generated, and so they can be ``%run``, imported from regular IPython sessions or other notebooks, or executed at the command line, as usual. Since we export the raw code you have typed, for these files to be importable from other code, you will have to avoid using syntax such as IPython magics and other IPython-specific extensions to the language.
440 431
441 In regular practice, the standard way to differentiate importable code from the
442 'executable' part of a script is to put at the bottom::
432 In normal Python practice, the standard way to differentiate importable code in a Python script from the "executable" part of a script is to use the following idiom at the start of the executable part of the code::
443 433
444 if __name__ == '__main__':
445 # rest of the code...
434 if __name__ == '__main__'
446 435
436 # rest of the code...
437
447 438 Since all cells in the notebook are run as top-level code, you will need to
448 439 similarly protect *all* cells that you do not want executed when other scripts
449 440 try to import your notebook. A convenient shortand for this is to define early
@@ -451,7 +442,7 b' on::'
451 442
452 443 script = __name__ == '__main__'
453 444
454 and then on any cell that you need to protect, use::
445 Then in any cell that you need to protect, use::
455 446
456 447 if script:
457 448 # rest of the cell...
@@ -462,7 +453,7 b' and then on any cell that you need to protect, use::'
462 453 Security
463 454 --------
464 455
465 You can protect your Notebook server with a simple singlepassword by
456 You can protect your Notebook server with a simple single password by
466 457 setting the :attr:`NotebookApp.password` configurable. You can prepare a
467 458 hashed password using the function :func:`IPython.lib.security.passwd`:
468 459
@@ -499,14 +490,14 b' communicate via a secure protocol mode using a self-signed certificate with the '
499 490
500 491 Your browser will warn you of a dangerous certificate because it is
501 492 self-signed. If you want to have a fully compliant certificate that will not
502 raise warnings, it is possible (but rather involved) to obtain one for free,
493 raise warnings, it is possible (but rather involved) to obtain one,
503 494 `as explained in detailed in this tutorial`__.
504 495
505 496 .. __: http://arstechnica.com/security/news/2009/12/how-to-get-set-with-a-secure-sertificate-for-free.ars
506 497
507 Keep in mind that when you enable SSL support, you'll need to access the
498 Keep in mind that when you enable SSL support, you will need to access the
508 499 notebook server over ``https://``, not over plain ``http://``. The startup
509 message from the server prints this, but it's easy to overlook and think the
500 message from the server prints this, but it is easy to overlook and think the
510 501 server is for some reason non-responsive.
511 502
512 503
@@ -514,23 +505,22 b' Connecting to an existing kernel'
514 505 ---------------------------------
515 506
516 507 The notebook server always prints to the terminal the full details of
517 how to connect to each kernel, with lines like::
508 how to connect to each kernel, with messages such as the following::
518 509
519 510 [IPKernelApp] To connect another client to this kernel, use:
520 511 [IPKernelApp] --existing kernel-3bb93edd-6b5a-455c-99c8-3b658f45dde5.json
521 512
522 This is the name of a JSON file that contains all the port and
523 validation information necessary to connect to the kernel. You can
524 manually start a Qt console with::
513 This long string is the name of a JSON file that contains all the port and
514 validation information necessary to connect to the kernel. You can then, for example, manually start a Qt console connected to the *same* kernel with::
525 515
526 516 ipython qtconsole --existing kernel-3bb93edd-6b5a-455c-99c8-3b658f45dde5.json
527 517
528 and if you only have a single kernel running, simply typing::
518 If you have only a single kernel running, simply typing::
529 519
530 520 ipython qtconsole --existing
531 521
532 will automatically find it (it will always find the most recently
533 started kernel if there is more than one). You can also request this
522 will automatically find it. (It will always find the most recently
523 started kernel if there is more than one.) You can also request this
534 524 connection data by typing ``%connect_info``; this will print the same
535 525 file information as well as the content of the JSON data structure it contains.
536 526
@@ -539,15 +529,13 b' Running a public notebook server'
539 529 --------------------------------
540 530
541 531 If you want to access your notebook server remotely with just a web browser,
542 here is a quick set of instructions. Start by creating a certificate file and
543 a hashed password as explained above. Then, create a custom profile for the
544 notebook. At the command line, type::
532 you can do the following.
533
534 Start by creating a certificate file and a hashed password, as explained above. Then, create a custom profile for the notebook: at the command line, type::
545 535
546 536 ipython profile create nbserver
547 537
548 In the profile directory, edit the file ``ipython_notebook_config.py``. By
549 default the file has all fields commented, the minimum set you need to
550 uncomment and edit is here::
538 In the profile directory just created, edit the file ``ipython_notebook_config.py``. By default, the file has all fields commented; the minimum set you need to uncomment and edit is the following::
551 539
552 540 c = get_config()
553 541
@@ -558,8 +546,8 b' uncomment and edit is here::'
558 546 c.NotebookApp.certfile = u'/absolute/path/to/your/certificate/mycert.pem'
559 547 c.NotebookApp.ip = '*'
560 548 c.NotebookApp.open_browser = False
561 c.NotebookApp.password = u'sha1:bcd259ccf...your hashed password here'
562 # It's a good idea to put it on a known, fixed port
549 c.NotebookApp.password = u'sha1:bcd259ccf...[your hashed password here]'
550 # It is a good idea to put it on a known, fixed port
563 551 c.NotebookApp.port = 9999
564 552
565 553 You can then start the notebook and access it later by pointing your browser to
General Comments 0
You need to be logged in to leave comments. Login now