##// END OF EJS Templates
Update docs logo to our current one, other minor fixes.
Fernando Perez -
Show More
1 NO CONTENT: modified file, binary diff hidden
@@ -1,1311 +1,1308 b''
1 1 =================
2 2 IPython reference
3 3 =================
4 4
5 5 .. _command_line_options:
6 6
7 7 Command-line usage
8 8 ==================
9 9
10 10 You start IPython with the command::
11 11
12 12 $ ipython [options] files
13 13
14 14 If invoked with no options, it executes all the files listed in sequence
15 15 and drops you into the interpreter while still acknowledging any options
16 16 you may have set in your ipython_config.py. This behavior is different from
17 17 standard Python, which when called as python -i will only execute one
18 18 file and ignore your configuration setup.
19 19
20 20 Please note that some of the configuration options are not available at
21 21 the command line, simply because they are not practical here. Look into
22 22 your ipythonrc configuration file for details on those. This file is typically
23 23 installed in the IPYTHON_DIR directory. For Linux
24 24 users, this will be $HOME/.config/ipython, and for other users it will be
25 25 $HOME/.ipython. For Windows users, $HOME resolves to C:\\Documents and
26 26 Settings\\YourUserName in most instances.
27 27
28 28
29 29 Eventloop integration
30 30 ---------------------
31 31
32 32 Previously IPython had command line options for controlling GUI event loop
33 33 integration (-gthread, -qthread, -q4thread, -wthread, -pylab). As of IPython
34 34 version 0.11, these have been removed. Please see the new ``%gui``
35 35 magic command or :ref:`this section <gui_support>` for details on the new
36 36 interface, or specify the gui at the commandline::
37 37
38 38 $ ipython --gui=qt
39 39
40 40
41 41 Regular Options
42 42 ---------------
43 43
44 44 After the above threading options have been given, regular options can
45 45 follow in any order. All options can be abbreviated to their shortest
46 46 non-ambiguous form and are case-sensitive. One or two dashes can be
47 47 used. Some options have an alternate short form, indicated after a ``|``.
48 48
49 49 Most options can also be set from your ipythonrc configuration file. See
50 50 the provided example for more details on what the options do. Options
51 51 given at the command line override the values set in the ipythonrc file.
52 52
53 53 All options with a [no] prepended can be specified in negated form
54 54 (--no-option instead of --option) to turn the feature off.
55 55
56 56 ``-h, --help`` print a help message and exit.
57 57
58 58 ``--pylab, pylab=<name>``
59 59 See :ref:`Matplotlib support <matplotlib_support>`
60 60 for more details.
61 61
62 62 ``--autocall=<val>``
63 63 Make IPython automatically call any callable object even if you
64 64 didn't type explicit parentheses. For example, 'str 43' becomes
65 65 'str(43)' automatically. The value can be '0' to disable the feature,
66 66 '1' for smart autocall, where it is not applied if there are no more
67 67 arguments on the line, and '2' for full autocall, where all callable
68 68 objects are automatically called (even if no arguments are
69 69 present). The default is '1'.
70 70
71 71 ``--[no-]autoindent``
72 72 Turn automatic indentation on/off.
73 73
74 74 ``--[no-]automagic``
75 75 make magic commands automatic (without needing their first character
76 76 to be %). Type %magic at the IPython prompt for more information.
77 77
78 78 ``--[no-]autoedit_syntax``
79 79 When a syntax error occurs after editing a file, automatically
80 80 open the file to the trouble causing line for convenient
81 81 fixing.
82 82
83 83 ``--[no-]banner``
84 84 Print the initial information banner (default on).
85 85
86 86 ``--c=<command>``
87 87 execute the given command string. This is similar to the -c
88 88 option in the normal Python interpreter.
89 89
90 90 ``--cache-size=<n>``
91 91 size of the output cache (maximum number of entries to hold in
92 92 memory). The default is 1000, you can change it permanently in your
93 93 config file. Setting it to 0 completely disables the caching system,
94 94 and the minimum value accepted is 20 (if you provide a value less than
95 95 20, it is reset to 0 and a warning is issued) This limit is defined
96 96 because otherwise you'll spend more time re-flushing a too small cache
97 97 than working.
98 98
99 99 ``--classic``
100 100 Gives IPython a similar feel to the classic Python
101 101 prompt.
102 102
103 103 ``--colors=<scheme>``
104 104 Color scheme for prompts and exception reporting. Currently
105 105 implemented: NoColor, Linux and LightBG.
106 106
107 107 ``--[no-]color_info``
108 108 IPython can display information about objects via a set of functions,
109 109 and optionally can use colors for this, syntax highlighting source
110 110 code and various other elements. However, because this information is
111 111 passed through a pager (like 'less') and many pagers get confused with
112 112 color codes, this option is off by default. You can test it and turn
113 113 it on permanently in your ipythonrc file if it works for you. As a
114 114 reference, the 'less' pager supplied with Mandrake 8.2 works ok, but
115 115 that in RedHat 7.2 doesn't.
116 116
117 117 Test it and turn it on permanently if it works with your
118 118 system. The magic function %color_info allows you to toggle this
119 119 interactively for testing.
120 120
121 121 ``--[no-]debug``
122 122 Show information about the loading process. Very useful to pin down
123 123 problems with your configuration files or to get details about
124 124 session restores.
125 125
126 126 ``--[no-]deep_reload``
127 127 IPython can use the deep_reload module which reloads changes in
128 128 modules recursively (it replaces the reload() function, so you don't
129 129 need to change anything to use it). deep_reload() forces a full
130 130 reload of modules whose code may have changed, which the default
131 131 reload() function does not.
132 132
133 133 When deep_reload is off, IPython will use the normal reload(),
134 134 but deep_reload will still be available as dreload(). This
135 135 feature is off by default [which means that you have both
136 136 normal reload() and dreload()].
137 137
138 138 ``--editor=<name>``
139 139 Which editor to use with the %edit command. By default,
140 140 IPython will honor your EDITOR environment variable (if not
141 141 set, vi is the Unix default and notepad the Windows one).
142 142 Since this editor is invoked on the fly by IPython and is
143 143 meant for editing small code snippets, you may want to use a
144 144 small, lightweight editor here (in case your default EDITOR is
145 145 something like Emacs).
146 146
147 147 ``--ipython_dir=<name>``
148 148 name of your IPython configuration directory IPYTHON_DIR. This
149 149 can also be specified through the environment variable
150 150 IPYTHON_DIR.
151 151
152 152 ``--logfile=<name>``
153 153 specify the name of your logfile.
154 154
155 155 This implies ``%logstart`` at the beginning of your session
156 156
157 157 generate a log file of all input. The file is named
158 158 ipython_log.py in your current directory (which prevents logs
159 159 from multiple IPython sessions from trampling each other). You
160 160 can use this to later restore a session by loading your
161 161 logfile with ``ipython --i ipython_log.py``
162 162
163 163 ``--logplay=<name>``
164 164
165 165 NOT AVAILABLE in 0.11
166 166
167 167 you can replay a previous log. For restoring a session as close as
168 168 possible to the state you left it in, use this option (don't just run
169 169 the logfile). With -logplay, IPython will try to reconstruct the
170 170 previous working environment in full, not just execute the commands in
171 171 the logfile.
172 172
173 173 When a session is restored, logging is automatically turned on
174 174 again with the name of the logfile it was invoked with (it is
175 175 read from the log header). So once you've turned logging on for
176 176 a session, you can quit IPython and reload it as many times as
177 177 you want and it will continue to log its history and restore
178 178 from the beginning every time.
179 179
180 180 Caveats: there are limitations in this option. The history
181 181 variables _i*,_* and _dh don't get restored properly. In the
182 182 future we will try to implement full session saving by writing
183 183 and retrieving a 'snapshot' of the memory state of IPython. But
184 184 our first attempts failed because of inherent limitations of
185 185 Python's Pickle module, so this may have to wait.
186 186
187 187 ``--[no-]messages``
188 188 Print messages which IPython collects about its startup
189 189 process (default on).
190 190
191 191 ``--[no-]pdb``
192 192 Automatically call the pdb debugger after every uncaught
193 193 exception. If you are used to debugging using pdb, this puts
194 194 you automatically inside of it after any call (either in
195 195 IPython or in code called by it) which triggers an exception
196 196 which goes uncaught.
197 197
198 198 ``--[no-]pprint``
199 199 ipython can optionally use the pprint (pretty printer) module
200 200 for displaying results. pprint tends to give a nicer display
201 201 of nested data structures. If you like it, you can turn it on
202 202 permanently in your config file (default off).
203 203
204 204 ``--profile=<name>``
205 205
206 206 Select the IPython profile by name.
207 207
208 208 This is a quick way to keep and load multiple
209 209 config files for different tasks, especially if you use the
210 210 include option of config files. You can keep a basic
211 211 :file:`IPYTHON_DIR/profile_default/ipython_config.py` file
212 212 and then have other 'profiles' which
213 213 include this one and load extra things for particular
214 214 tasks. For example:
215 215
216 216 1. $IPYTHON_DIR/profile_default : load basic things you always want.
217 217 2. $IPYTHON_DIR/profile_math : load (1) and basic math-related modules.
218 218 3. $IPYTHON_DIR/profile_numeric : load (1) and Numeric and plotting modules.
219 219
220 220 Since it is possible to create an endless loop by having
221 221 circular file inclusions, IPython will stop if it reaches 15
222 222 recursive inclusions.
223 223
224 224 ``InteractiveShell.prompt_in1=<string>``
225 225
226 226 Specify the string used for input prompts. Note that if you are using
227 227 numbered prompts, the number is represented with a '\#' in the
228 228 string. Don't forget to quote strings with spaces embedded in
229 229 them. Default: 'In [\#]:'. The :ref:`prompts section <prompts>`
230 230 discusses in detail all the available escapes to customize your
231 231 prompts.
232 232
233 233 ``InteractiveShell.prompt_in2=<string>``
234 234 Similar to the previous option, but used for the continuation
235 235 prompts. The special sequence '\D' is similar to '\#', but
236 236 with all digits replaced dots (so you can have your
237 237 continuation prompt aligned with your input prompt). Default:
238 238 ' .\D.:' (note three spaces at the start for alignment with
239 239 'In [\#]').
240 240
241 241 ``InteractiveShell.prompt_out=<string>``
242 242 String used for output prompts, also uses numbers like
243 243 prompt_in1. Default: 'Out[\#]:'
244 244
245 245 ``--quick``
246 246 start in bare bones mode (no config file loaded).
247 247
248 248 ``config_file=<name>``
249 249 name of your IPython resource configuration file. Normally
250 250 IPython loads ipython_config.py (from current directory) or
251 251 IPYTHON_DIR/profile_default.
252 252
253 253 If the loading of your config file fails, IPython starts with
254 254 a bare bones configuration (no modules loaded at all).
255 255
256 256 ``--[no-]readline``
257 257 use the readline library, which is needed to support name
258 258 completion and command history, among other things. It is
259 259 enabled by default, but may cause problems for users of
260 260 X/Emacs in Python comint or shell buffers.
261 261
262 262 Note that X/Emacs 'eterm' buffers (opened with M-x term) support
263 263 IPython's readline and syntax coloring fine, only 'emacs' (M-x
264 264 shell and C-c !) buffers do not.
265 265
266 266 ``--TerminalInteractiveShell.screen_length=<n>``
267 267 number of lines of your screen. This is used to control
268 268 printing of very long strings. Strings longer than this number
269 269 of lines will be sent through a pager instead of directly
270 270 printed.
271 271
272 272 The default value for this is 0, which means IPython will
273 273 auto-detect your screen size every time it needs to print certain
274 274 potentially long strings (this doesn't change the behavior of the
275 275 'print' keyword, it's only triggered internally). If for some
276 276 reason this isn't working well (it needs curses support), specify
277 277 it yourself. Otherwise don't change the default.
278 278
279 279 ``--TerminalInteractiveShell.separate_in=<string>``
280 280
281 281 separator before input prompts.
282 282 Default: '\n'
283 283
284 284 ``--TerminalInteractiveShell.separate_out=<string>``
285 285 separator before output prompts.
286 286 Default: nothing.
287 287
288 288 ``--TerminalInteractiveShell.separate_out2=<string>``
289 289 separator after output prompts.
290 290 Default: nothing.
291 291 For these three options, use the value 0 to specify no separator.
292 292
293 293 ``--nosep``
294 294 shorthand for setting the above separators to empty strings.
295 295
296 296 Simply removes all input/output separators.
297 297
298 298 ``--init``
299 299 allows you to initialize a profile dir for configuration when you
300 300 install a new version of IPython or want to use a new profile.
301 301 Since new versions may include new command line options or example
302 302 files, this copies updated config files. Note that you should probably
303 303 use %upgrade instead,it's a safer alternative.
304 304
305 305 ``--version`` print version information and exit.
306 306
307 307 ``--xmode=<modename>``
308 308
309 309 Mode for exception reporting.
310 310
311 311 Valid modes: Plain, Context and Verbose.
312 312
313 313 * Plain: similar to python's normal traceback printing.
314 314 * Context: prints 5 lines of context source code around each
315 315 line in the traceback.
316 316 * Verbose: similar to Context, but additionally prints the
317 317 variables currently visible where the exception happened
318 318 (shortening their strings if too long). This can potentially be
319 319 very slow, if you happen to have a huge data structure whose
320 320 string representation is complex to compute. Your computer may
321 321 appear to freeze for a while with cpu usage at 100%. If this
322 322 occurs, you can cancel the traceback with Ctrl-C (maybe hitting it
323 323 more than once).
324 324
325 325 Interactive use
326 326 ===============
327 327
328 IPython is meant to work as a drop-in
329 replacement for the standard interactive interpreter. As such, any code
330 which is valid python should execute normally under IPython (cases where
331 this is not true should be reported as bugs). It does, however, offer
332 many features which are not available at a standard python prompt. What
333 follows is a list of these.
328 IPython is meant to work as a drop-in replacement for the standard interactive
329 interpreter. As such, any code which is valid python should execute normally
330 under IPython (cases where this is not true should be reported as bugs). It
331 does, however, offer many features which are not available at a standard python
332 prompt. What follows is a list of these.
334 333
335 334
336 335 Caution for Windows users
337 336 -------------------------
338 337
339 Windows, unfortunately, uses the '\\' character as a path
340 separator. This is a terrible choice, because '\\' also represents the
341 escape character in most modern programming languages, including
342 Python. For this reason, using '/' character is recommended if you
343 have problems with ``\``. However, in Windows commands '/' flags
344 options, so you can not use it for the root directory. This means that
345 paths beginning at the root must be typed in a contrived manner like:
346 ``%copy \opt/foo/bar.txt \tmp``
338 Windows, unfortunately, uses the '\\' character as a path separator. This is a
339 terrible choice, because '\\' also represents the escape character in most
340 modern programming languages, including Python. For this reason, using '/'
341 character is recommended if you have problems with ``\``. However, in Windows
342 commands '/' flags options, so you can not use it for the root directory. This
343 means that paths beginning at the root must be typed in a contrived manner
344 like: ``%copy \opt/foo/bar.txt \tmp``
347 345
348 346 .. _magic:
349 347
350 348 Magic command system
351 349 --------------------
352 350
353 351 IPython will treat any line whose first character is a % as a special
354 352 call to a 'magic' function. These allow you to control the behavior of
355 353 IPython itself, plus a lot of system-type features. They are all
356 354 prefixed with a % character, but parameters are given without
357 355 parentheses or quotes.
358 356
359 357 Example: typing ``%cd mydir`` changes your working directory to 'mydir', if it
360 358 exists.
361 359
362 360 If you have 'automagic' enabled (as it by default), you don't need
363 361 to type in the % explicitly. IPython will scan its internal list of
364 362 magic functions and call one if it exists. With automagic on you can
365 363 then just type ``cd mydir`` to go to directory 'mydir'. The automagic
366 364 system has the lowest possible precedence in name searches, so defining
367 365 an identifier with the same name as an existing magic function will
368 366 shadow it for automagic use. You can still access the shadowed magic
369 367 function by explicitly using the % character at the beginning of the line.
370 368
371 369 An example (with automagic on) should clarify all this:
372 370
373 371 .. sourcecode:: ipython
374 372
375 373 In [1]: cd ipython # %cd is called by automagic
376 374
377 375 /home/fperez/ipython
378 376
379 377 In [2]: cd=1 # now cd is just a variable
380 378
381 379 In [3]: cd .. # and doesn't work as a function anymore
382 380
383 381 ------------------------------
384 382
385 383 File "<console>", line 1
386 384
387 385 cd ..
388 386
389 387 ^
390 388
391 389 SyntaxError: invalid syntax
392 390
393 391 In [4]: %cd .. # but %cd always works
394 392
395 393 /home/fperez
396 394
397 395 In [5]: del cd # if you remove the cd variable
398 396
399 397 In [6]: cd ipython # automagic can work again
400 398
401 399 /home/fperez/ipython
402 400
403 401 You can define your own magic functions to extend the system. The
404 402 following example defines a new magic command, %impall:
405 403
406 404 .. sourcecode:: python
407 405
408 406 ip = get_ipython()
409 407
410 408 def doimp(self, arg):
411 409
412 410 ip = self.api
413 411
414 412 ip.ex("import %s; reload(%s); from %s import *" % (
415 413
416 414 arg,arg,arg)
417 415
418 416 )
419 417
420 418 ip.expose_magic('impall', doimp)
421 419
422 Type %magic for more information, including a list of all available
423 magic functions at any time and their docstrings. You can also type
424 %magic_function_name? (see sec. 6.4 <#sec:dyn-object-info> for
425 information on the '?' system) to get information about any particular
426 magic function you are interested in.
420 Type `%magic` for more information, including a list of all available magic
421 functions at any time and their docstrings. You can also type
422 %magic_function_name? (see :ref:`below <dynamic_object_info` for information on
423 the '?' system) to get information about any particular magic function you are
424 interested in.
427 425
428 426 The API documentation for the :mod:`IPython.core.magic` module contains the full
429 427 docstrings of all currently available magic commands.
430 428
431 429
432 430 Access to the standard Python help
433 431 ----------------------------------
434 432
435 433 As of Python 2.1, a help system is available with access to object docstrings
436 434 and the Python manuals. Simply type 'help' (no quotes) to access it. You can
437 435 also type help(object) to obtain information about a given object, and
438 436 help('keyword') for information on a keyword. As noted :ref:`here
439 437 <accessing_help>`, you need to properly configure your environment variable
440 438 PYTHONDOCS for this feature to work correctly.
441 439
442 440 .. _dynamic_object_info:
443 441
444 442 Dynamic object information
445 443 --------------------------
446 444
447 Typing ?word or word? prints detailed information about an object. If
448 certain strings in the object are too long (docstrings, code, etc.) they
449 get snipped in the center for brevity. This system gives access variable
450 types and values, full source code for any object (if available),
451 function prototypes and other useful information.
445 Typing ``?word`` or ``word?`` prints detailed information about an object. If
446 certain strings in the object are too long (docstrings, code, etc.) they get
447 snipped in the center for brevity. This system gives access variable types and
448 values, full source code for any object (if available), function prototypes and
449 other useful information.
452 450
453 Typing ??word or word?? gives access to the full information without
451 Typing ``??word`` or ``word??`` gives access to the full information without
454 452 snipping long strings. Long strings are sent to the screen through the
455 453 less pager if longer than the screen and printed otherwise. On systems
456 454 lacking the less command, IPython uses a very basic internal pager.
457 455
458 456 The following magic functions are particularly useful for gathering
459 457 information about your working environment. You can get more details by
460 typing %magic or querying them individually (use %function_name? with or
458 typing ``%magic`` or querying them individually (use %function_name? with or
461 459 without the %), this is just a summary:
462 460
463 461 * **%pdoc <object>**: Print (or run through a pager if too long) the
464 462 docstring for an object. If the given object is a class, it will
465 463 print both the class and the constructor docstrings.
466 464 * **%pdef <object>**: Print the definition header for any callable
467 465 object. If the object is a class, print the constructor information.
468 466 * **%psource <object>**: Print (or run through a pager if too long)
469 467 the source code for an object.
470 468 * **%pfile <object>**: Show the entire source file where an object was
471 469 defined via a pager, opening it at the line where the object
472 470 definition begins.
473 471 * **%who/%whos**: These functions give information about identifiers
474 472 you have defined interactively (not things you loaded or defined
475 473 in your configuration files). %who just prints a list of
476 474 identifiers and %whos prints a table with some basic details about
477 475 each identifier.
478 476
479 Note that the dynamic object information functions (?/??, %pdoc, %pfile,
480 %pdef, %psource) give you access to documentation even on things which
481 are not really defined as separate identifiers. Try for example typing
482 {}.get? or after doing import os, type os.path.abspath??.
483
477 Note that the dynamic object information functions (?/??, ``%pdoc``,
478 ``%pfile``, ``%pdef``, ``%psource``) give you access to documentation even on
479 things which are not really defined as separate identifiers. Try for example
480 typing {}.get? or after doing import os, type ``os.path.abspath??``.
484 481
485 482 .. _readline:
486 483
487 484 Readline-based features
488 485 -----------------------
489 486
490 These features require the GNU readline library, so they won't work if
491 your Python installation lacks readline support. We will first describe
492 the default behavior IPython uses, and then how to change it to suit
493 your preferences.
487 These features require the GNU readline library, so they won't work if your
488 Python installation lacks readline support. We will first describe the default
489 behavior IPython uses, and then how to change it to suit your preferences.
494 490
495 491
496 492 Command line completion
497 493 +++++++++++++++++++++++
498 494
499 495 At any time, hitting TAB will complete any available python commands or
500 496 variable names, and show you a list of the possible completions if
501 497 there's no unambiguous one. It will also complete filenames in the
502 498 current directory if no python names match what you've typed so far.
503 499
504 500
505 501 Search command history
506 502 ++++++++++++++++++++++
507 503
508 504 IPython provides two ways for searching through previous input and thus
509 505 reduce the need for repetitive typing:
510 506
511 507 1. Start typing, and then use Ctrl-p (previous,up) and Ctrl-n
512 508 (next,down) to search through only the history items that match
513 509 what you've typed so far. If you use Ctrl-p/Ctrl-n at a blank
514 510 prompt, they just behave like normal arrow keys.
515 511 2. Hit Ctrl-r: opens a search prompt. Begin typing and the system
516 512 searches your history for lines that contain what you've typed so
517 513 far, completing as much as it can.
518 514
519 515
520 516 Persistent command history across sessions
521 517 ++++++++++++++++++++++++++++++++++++++++++
522 518
523 519 IPython will save your input history when it leaves and reload it next
524 520 time you restart it. By default, the history file is named
525 521 $IPYTHON_DIR/profile_<name>/history.sqlite. This allows you to keep
526 522 separate histories related to various tasks: commands related to
527 523 numerical work will not be clobbered by a system shell history, for
528 524 example.
529 525
530 526
531 527 Autoindent
532 528 ++++++++++
533 529
534 530 IPython can recognize lines ending in ':' and indent the next line,
535 531 while also un-indenting automatically after 'raise' or 'return'.
536 532
537 This feature uses the readline library, so it will honor your ~/.inputrc
538 configuration (or whatever file your INPUTRC variable points to). Adding
539 the following lines to your .inputrc file can make indenting/unindenting
540 more convenient (M-i indents, M-u unindents)::
533 This feature uses the readline library, so it will honor your
534 :file:`~/.inputrc` configuration (or whatever file your INPUTRC variable points
535 to). Adding the following lines to your :file:`.inputrc` file can make
536 indenting/unindenting more convenient (M-i indents, M-u unindents)::
541 537
542 538 $if Python
543 539 "\M-i": " "
544 540 "\M-u": "\d\d\d\d"
545 541 $endif
546 542
547 543 Note that there are 4 spaces between the quote marks after "M-i" above.
548 544
549 545 .. warning::
550 546
551 Setting the above indents will cause problems with unicode text entry in the terminal.
547 Setting the above indents will cause problems with unicode text entry in
548 the terminal.
552 549
553 550 .. warning::
554 551
555 Autoindent is ON by default, but it can cause problems with
556 the pasting of multi-line indented code (the pasted code gets
557 re-indented on each line). A magic function %autoindent allows you to
558 toggle it on/off at runtime. You can also disable it permanently on in
559 your :file:`ipython_config.py` file (set TerminalInteractiveShell.autoindent=False).
552 Autoindent is ON by default, but it can cause problems with the pasting of
553 multi-line indented code (the pasted code gets re-indented on each line). A
554 magic function %autoindent allows you to toggle it on/off at runtime. You
555 can also disable it permanently on in your :file:`ipython_config.py` file
556 (set TerminalInteractiveShell.autoindent=False).
560 557
561 If you want to paste multiple lines, it is recommended that you use ``%paste``.
558 If you want to paste multiple lines, it is recommended that you use
559 ``%paste``.
562 560
563 561
564 562 Customizing readline behavior
565 563 +++++++++++++++++++++++++++++
566 564
567 565 All these features are based on the GNU readline library, which has an
568 566 extremely customizable interface. Normally, readline is configured via a
569 567 file which defines the behavior of the library; the details of the
570 568 syntax for this can be found in the readline documentation available
571 569 with your system or on the Internet. IPython doesn't read this file (if
572 570 it exists) directly, but it does support passing to readline valid
573 571 options via a simple interface. In brief, you can customize readline by
574 572 setting the following options in your ipythonrc configuration file (note
575 573 that these options can not be specified at the command line):
576 574
577 575 * **readline_parse_and_bind**: this option can appear as many times as
578 576 you want, each time defining a string to be executed via a
579 577 readline.parse_and_bind() command. The syntax for valid commands
580 578 of this kind can be found by reading the documentation for the GNU
581 579 readline library, as these commands are of the kind which readline
582 580 accepts in its configuration file.
583 581 * **readline_remove_delims**: a string of characters to be removed
584 582 from the default word-delimiters list used by readline, so that
585 583 completions may be performed on strings which contain them. Do not
586 584 change the default value unless you know what you're doing.
587 585 * **readline_omit__names**: when tab-completion is enabled, hitting
588 586 <tab> after a '.' in a name will complete all attributes of an
589 587 object, including all the special methods whose names include
590 588 double underscores (like __getitem__ or __class__). If you'd
591 589 rather not see these names by default, you can set this option to
592 590 1. Note that even when this option is set, you can still see those
593 591 names by explicitly typing a _ after the period and hitting <tab>:
594 592 'name._<tab>' will always complete attribute names starting with '_'.
595 593
596 594 This option is off by default so that new users see all
597 595 attributes of any objects they are dealing with.
598 596
599 597 You will find the default values along with a corresponding detailed
600 598 explanation in your ipythonrc file.
601 599
602 600
603 601 Session logging and restoring
604 602 -----------------------------
605 603
606 604 You can log all input from a session either by starting IPython with the
607 605 command line switch ``--logfile=foo.py`` (see :ref:`here <command_line_options>`)
608 606 or by activating the logging at any moment with the magic function %logstart.
609 607
610 608 Log files can later be reloaded by running them as scripts and IPython
611 609 will attempt to 'replay' the log by executing all the lines in it, thus
612 610 restoring the state of a previous session. This feature is not quite
613 611 perfect, but can still be useful in many cases.
614 612
615 613 The log files can also be used as a way to have a permanent record of
616 614 any code you wrote while experimenting. Log files are regular text files
617 615 which you can later open in your favorite text editor to extract code or
618 616 to 'clean them up' before using them to replay a session.
619 617
620 The %logstart function for activating logging in mid-session is used as
621 follows:
618 The `%logstart` function for activating logging in mid-session is used as
619 follows::
622 620
623 %logstart [log_name [log_mode]]
621 %logstart [log_name [log_mode]]
624 622
625 623 If no name is given, it defaults to a file named 'ipython_log.py' in your
626 624 current working directory, in 'rotate' mode (see below).
627 625
628 626 '%logstart name' saves to file 'name' in 'backup' mode. It saves your
629 627 history up to that point and then continues logging.
630 628
631 629 %logstart takes a second optional parameter: logging mode. This can be
632 630 one of (note that the modes are given unquoted):
633 631
634 632 * [over:] overwrite existing log_name.
635 633 * [backup:] rename (if exists) to log_name~ and start log_name.
636 634 * [append:] well, that says it.
637 635 * [rotate:] create rotating logs log_name.1~, log_name.2~, etc.
638 636
639 637 The %logoff and %logon functions allow you to temporarily stop and
640 638 resume logging to a file which had previously been started with
641 639 %logstart. They will fail (with an explanation) if you try to use them
642 640 before logging has been started.
643 641
644 642 .. _system_shell_access:
645 643
646 644 System shell access
647 645 -------------------
648 646
649 647 Any input line beginning with a ! character is passed verbatim (minus
650 648 the !, of course) to the underlying operating system. For example,
651 649 typing ``!ls`` will run 'ls' in the current directory.
652 650
653 651 Manual capture of command output
654 652 --------------------------------
655 653
656 654 If the input line begins with two exclamation marks, !!, the command is
657 655 executed but its output is captured and returned as a python list, split
658 656 on newlines. Any output sent by the subprocess to standard error is
659 657 printed separately, so that the resulting list only captures standard
660 658 output. The !! syntax is a shorthand for the %sx magic command.
661 659
662 660 Finally, the %sc magic (short for 'shell capture') is similar to %sx,
663 661 but allowing more fine-grained control of the capture details, and
664 662 storing the result directly into a named variable. The direct use of
665 663 %sc is now deprecated, and you should ise the ``var = !cmd`` syntax
666 664 instead.
667 665
668 666 IPython also allows you to expand the value of python variables when
669 667 making system calls. Any python variable or expression which you prepend
670 668 with $ will get expanded before the system call is made::
671 669
672 670 In [1]: pyvar='Hello world'
673 671 In [2]: !echo "A python variable: $pyvar"
674 672 A python variable: Hello world
675 673
676 674 If you want the shell to actually see a literal $, you need to type it
677 675 twice::
678 676
679 677 In [3]: !echo "A system variable: $$HOME"
680 678 A system variable: /home/fperez
681 679
682 680 You can pass arbitrary expressions, though you'll need to delimit them
683 681 with {} if there is ambiguity as to the extent of the expression::
684 682
685 683 In [5]: x=10
686 684 In [6]: y=20
687 685 In [13]: !echo $x+y
688 686 10+y
689 687 In [7]: !echo ${x+y}
690 688 30
691 689
692 690 Even object attributes can be expanded::
693 691
694 692 In [12]: !echo $sys.argv
695 693 [/home/fperez/usr/bin/ipython]
696 694
697 695
698 696 System command aliases
699 697 ----------------------
700 698
701 699 The %alias magic function and the alias option in the ipythonrc
702 700 configuration file allow you to define magic functions which are in fact
703 701 system shell commands. These aliases can have parameters.
704 702
705 703 ``%alias alias_name cmd`` defines 'alias_name' as an alias for 'cmd'
706 704
707 705 Then, typing ``%alias_name params`` will execute the system command 'cmd
708 706 params' (from your underlying operating system).
709 707
710 708 You can also define aliases with parameters using %s specifiers (one per
711 709 parameter). The following example defines the %parts function as an
712 710 alias to the command 'echo first %s second %s' where each %s will be
713 711 replaced by a positional parameter to the call to %parts::
714 712
715 713 In [1]: alias parts echo first %s second %s
716 714 In [2]: %parts A B
717 715 first A second B
718 716 In [3]: %parts A
719 717 Incorrect number of arguments: 2 expected.
720 718 parts is an alias to: 'echo first %s second %s'
721 719
722 720 If called with no parameters, %alias prints the table of currently
723 721 defined aliases.
724 722
725 723 The %rehashx magic allows you to load your entire $PATH as
726 724 ipython aliases. See its docstring for further details.
727 725
728 726
729 727 .. _dreload:
730 728
731 729 Recursive reload
732 730 ----------------
733 731
734 732 The dreload function does a recursive reload of a module: changes made
735 733 to the module since you imported will actually be available without
736 734 having to exit.
737 735
738 736
739 737 Verbose and colored exception traceback printouts
740 738 -------------------------------------------------
741 739
742 740 IPython provides the option to see very detailed exception tracebacks,
743 741 which can be especially useful when debugging large programs. You can
744 742 run any Python file with the %run function to benefit from these
745 743 detailed tracebacks. Furthermore, both normal and verbose tracebacks can
746 744 be colored (if your terminal supports it) which makes them much easier
747 745 to parse visually.
748 746
749 747 See the magic xmode and colors functions for details (just type %magic).
750 748
751 749 These features are basically a terminal version of Ka-Ping Yee's cgitb
752 750 module, now part of the standard Python library.
753 751
754 752
755 753 .. _input_caching:
756 754
757 755 Input caching system
758 756 --------------------
759 757
760 758 IPython offers numbered prompts (In/Out) with input and output caching
761 759 (also referred to as 'input history'). All input is saved and can be
762 760 retrieved as variables (besides the usual arrow key recall), in
763 761 addition to the %rep magic command that brings a history entry
764 762 up for editing on the next command line.
765 763
766 764 The following GLOBAL variables always exist (so don't overwrite them!):
767 765
768 766 * _i, _ii, _iii: store previous, next previous and next-next previous inputs.
769 767 * In, _ih : a list of all inputs; _ih[n] is the input from line n. If you
770 768 overwrite In with a variable of your own, you can remake the assignment to the
771 769 internal list with a simple ``In=_ih``.
772 770
773 771 Additionally, global variables named _i<n> are dynamically created (<n>
774 772 being the prompt counter), so ``_i<n> == _ih[<n>] == In[<n>]``.
775 773
776 774 For example, what you typed at prompt 14 is available as _i14, _ih[14]
777 775 and In[14].
778 776
779 777 This allows you to easily cut and paste multi line interactive prompts
780 778 by printing them out: they print like a clean string, without prompt
781 779 characters. You can also manipulate them like regular variables (they
782 780 are strings), modify or exec them (typing ``exec _i9`` will re-execute the
783 781 contents of input prompt 9.
784 782
785 783 You can also re-execute multiple lines of input easily by using the
786 784 magic %macro function (which automates the process and allows
787 785 re-execution without having to type 'exec' every time). The macro system
788 786 also allows you to re-execute previous lines which include magic
789 787 function calls (which require special processing). Type %macro? for more details
790 788 on the macro system.
791 789
792 790 A history function %hist allows you to see any part of your input
793 791 history by printing a range of the _i variables.
794 792
795 793 You can also search ('grep') through your history by typing
796 794 ``%hist -g somestring``. This is handy for searching for URLs, IP addresses,
797 795 etc. You can bring history entries listed by '%hist -g' up for editing
798 796 with the %recall command, or run them immediately with %rerun.
799 797
800 798 .. _output_caching:
801 799
802 800 Output caching system
803 801 ---------------------
804 802
805 803 For output that is returned from actions, a system similar to the input
806 804 cache exists but using _ instead of _i. Only actions that produce a
807 805 result (NOT assignments, for example) are cached. If you are familiar
808 806 with Mathematica, IPython's _ variables behave exactly like
809 807 Mathematica's % variables.
810 808
811 809 The following GLOBAL variables always exist (so don't overwrite them!):
812 810
813 811 * [_] (a single underscore) : stores previous output, like Python's
814 812 default interpreter.
815 813 * [__] (two underscores): next previous.
816 814 * [___] (three underscores): next-next previous.
817 815
818 816 Additionally, global variables named _<n> are dynamically created (<n>
819 817 being the prompt counter), such that the result of output <n> is always
820 818 available as _<n> (don't use the angle brackets, just the number, e.g.
821 819 _21).
822 820
823 821 These global variables are all stored in a global dictionary (not a
824 822 list, since it only has entries for lines which returned a result)
825 823 available under the names _oh and Out (similar to _ih and In). So the
826 824 output from line 12 can be obtained as _12, Out[12] or _oh[12]. If you
827 825 accidentally overwrite the Out variable you can recover it by typing
828 826 'Out=_oh' at the prompt.
829 827
830 828 This system obviously can potentially put heavy memory demands on your
831 829 system, since it prevents Python's garbage collector from removing any
832 830 previously computed results. You can control how many results are kept
833 831 in memory with the option (at the command line or in your ipythonrc
834 832 file) cache_size. If you set it to 0, the whole system is completely
835 833 disabled and the prompts revert to the classic '>>>' of normal Python.
836 834
837 835
838 836 Directory history
839 837 -----------------
840 838
841 839 Your history of visited directories is kept in the global list _dh, and
842 840 the magic %cd command can be used to go to any entry in that list. The
843 841 %dhist command allows you to view this history. Do ``cd -<TAB>`` to
844 842 conveniently view the directory history.
845 843
846 844
847 845 Automatic parentheses and quotes
848 846 --------------------------------
849 847
850 848 These features were adapted from Nathan Gray's LazyPython. They are
851 849 meant to allow less typing for common situations.
852 850
853 851
854 852 Automatic parentheses
855 853 ---------------------
856 854
857 855 Callable objects (i.e. functions, methods, etc) can be invoked like this
858 856 (notice the commas between the arguments)::
859 857
860 858 >>> callable_ob arg1, arg2, arg3
861 859
862 860 and the input will be translated to this::
863 861
864 862 -> callable_ob(arg1, arg2, arg3)
865 863
866 864 You can force automatic parentheses by using '/' as the first character
867 865 of a line. For example::
868 866
869 867 >>> /globals # becomes 'globals()'
870 868
871 869 Note that the '/' MUST be the first character on the line! This won't work::
872 870
873 871 >>> print /globals # syntax error
874 872
875 873 In most cases the automatic algorithm should work, so you should rarely
876 874 need to explicitly invoke /. One notable exception is if you are trying
877 875 to call a function with a list of tuples as arguments (the parenthesis
878 876 will confuse IPython)::
879 877
880 878 In [1]: zip (1,2,3),(4,5,6) # won't work
881 879
882 880 but this will work::
883 881
884 882 In [2]: /zip (1,2,3),(4,5,6)
885 883 ---> zip ((1,2,3),(4,5,6))
886 884 Out[2]= [(1, 4), (2, 5), (3, 6)]
887 885
888 886 IPython tells you that it has altered your command line by displaying
889 887 the new command line preceded by ->. e.g.::
890 888
891 889 In [18]: callable list
892 890 ----> callable (list)
893 891
894 892
895 893 Automatic quoting
896 894 -----------------
897 895
898 896 You can force automatic quoting of a function's arguments by using ','
899 897 or ';' as the first character of a line. For example::
900 898
901 899 >>> ,my_function /home/me # becomes my_function("/home/me")
902 900
903 901 If you use ';' instead, the whole argument is quoted as a single string
904 902 (while ',' splits on whitespace)::
905 903
906 904 >>> ,my_function a b c # becomes my_function("a","b","c")
907 905
908 906 >>> ;my_function a b c # becomes my_function("a b c")
909 907
910 908 Note that the ',' or ';' MUST be the first character on the line! This
911 909 won't work::
912 910
913 911 >>> x = ,my_function /home/me # syntax error
914 912
915 913 IPython as your default Python environment
916 914 ==========================================
917 915
918 916 Python honors the environment variable PYTHONSTARTUP and will execute at
919 917 startup the file referenced by this variable. If you put at the end of
920 918 this file the following two lines of code::
921 919
922 920 from IPython.frontend.terminal.ipapp import launch_new_instance
923 921 launch_new_instance()
924 922 raise SystemExit
925 923
926 924 then IPython will be your working environment anytime you start Python.
927 925 The ``raise SystemExit`` is needed to exit Python when
928 926 it finishes, otherwise you'll be back at the normal Python '>>>'
929 927 prompt.
930 928
931 929 This is probably useful to developers who manage multiple Python
932 930 versions and don't want to have correspondingly multiple IPython
933 931 versions. Note that in this mode, there is no way to pass IPython any
934 932 command-line options, as those are trapped first by Python itself.
935 933
936 934 .. _Embedding:
937 935
938 936 Embedding IPython
939 937 =================
940 938
941 939 It is possible to start an IPython instance inside your own Python
942 940 programs. This allows you to evaluate dynamically the state of your
943 941 code, operate with your variables, analyze them, etc. Note however that
944 942 any changes you make to values while in the shell do not propagate back
945 943 to the running code, so it is safe to modify your values because you
946 944 won't break your code in bizarre ways by doing so.
947 945
948 946 This feature allows you to easily have a fully functional python
949 947 environment for doing object introspection anywhere in your code with a
950 948 simple function call. In some cases a simple print statement is enough,
951 949 but if you need to do more detailed analysis of a code fragment this
952 950 feature can be very valuable.
953 951
954 952 It can also be useful in scientific computing situations where it is
955 953 common to need to do some automatic, computationally intensive part and
956 954 then stop to look at data, plots, etc.
957 955 Opening an IPython instance will give you full access to your data and
958 956 functions, and you can resume program execution once you are done with
959 957 the interactive part (perhaps to stop again later, as many times as
960 958 needed).
961 959
962 960 The following code snippet is the bare minimum you need to include in
963 961 your Python programs for this to work (detailed examples follow later)::
964 962
965 963 from IPython import embed
966 964
967 965 embed() # this call anywhere in your program will start IPython
968 966
969 967 You can run embedded instances even in code which is itself being run at
970 968 the IPython interactive prompt with '%run <filename>'. Since it's easy
971 969 to get lost as to where you are (in your top-level IPython or in your
972 970 embedded one), it's a good idea in such cases to set the in/out prompts
973 971 to something different for the embedded instances. The code examples
974 972 below illustrate this.
975 973
976 974 You can also have multiple IPython instances in your program and open
977 975 them separately, for example with different options for data
978 976 presentation. If you close and open the same instance multiple times,
979 977 its prompt counters simply continue from each execution to the next.
980 978
981 979 Please look at the docstrings in the :mod:`~IPython.frontend.terminal.embed`
982 980 module for more details on the use of this system.
983 981
984 982 The following sample file illustrating how to use the embedding
985 983 functionality is provided in the examples directory as example-embed.py.
986 984 It should be fairly self-explanatory:
987 985
988 986 .. literalinclude:: ../../examples/core/example-embed.py
989 987 :language: python
990 988
991 989 Once you understand how the system functions, you can use the following
992 990 code fragments in your programs which are ready for cut and paste:
993 991
994 992 .. literalinclude:: ../../examples/core/example-embed-short.py
995 993 :language: python
996 994
997 995 Using the Python debugger (pdb)
998 996 ===============================
999 997
1000 998 Running entire programs via pdb
1001 999 -------------------------------
1002 1000
1003 1001 pdb, the Python debugger, is a powerful interactive debugger which
1004 1002 allows you to step through code, set breakpoints, watch variables,
1005 1003 etc. IPython makes it very easy to start any script under the control
1006 1004 of pdb, regardless of whether you have wrapped it into a 'main()'
1007 1005 function or not. For this, simply type '%run -d myscript' at an
1008 1006 IPython prompt. See the %run command's documentation (via '%run?' or
1009 1007 in Sec. magic_ for more details, including how to control where pdb
1010 1008 will stop execution first.
1011 1009
1012 1010 For more information on the use of the pdb debugger, read the included
1013 1011 pdb.doc file (part of the standard Python distribution). On a stock
1014 1012 Linux system it is located at /usr/lib/python2.3/pdb.doc, but the
1015 1013 easiest way to read it is by using the help() function of the pdb module
1016 1014 as follows (in an IPython prompt)::
1017 1015
1018 1016 In [1]: import pdb
1019 1017 In [2]: pdb.help()
1020 1018
1021 1019 This will load the pdb.doc document in a file viewer for you automatically.
1022 1020
1023 1021
1024 1022 Automatic invocation of pdb on exceptions
1025 1023 -----------------------------------------
1026 1024
1027 1025 IPython, if started with the -pdb option (or if the option is set in
1028 1026 your rc file) can call the Python pdb debugger every time your code
1029 1027 triggers an uncaught exception. This feature
1030 1028 can also be toggled at any time with the %pdb magic command. This can be
1031 1029 extremely useful in order to find the origin of subtle bugs, because pdb
1032 1030 opens up at the point in your code which triggered the exception, and
1033 1031 while your program is at this point 'dead', all the data is still
1034 1032 available and you can walk up and down the stack frame and understand
1035 1033 the origin of the problem.
1036 1034
1037 1035 Furthermore, you can use these debugging facilities both with the
1038 1036 embedded IPython mode and without IPython at all. For an embedded shell
1039 1037 (see sec. Embedding_), simply call the constructor with
1040 1038 '--pdb' in the argument string and automatically pdb will be called if an
1041 1039 uncaught exception is triggered by your code.
1042 1040
1043 1041 For stand-alone use of the feature in your programs which do not use
1044 1042 IPython at all, put the following lines toward the top of your 'main'
1045 1043 routine::
1046 1044
1047 1045 import sys
1048 1046 from IPython.core import ultratb
1049 1047 sys.excepthook = ultratb.FormattedTB(mode='Verbose',
1050 1048 color_scheme='Linux', call_pdb=1)
1051 1049
1052 1050 The mode keyword can be either 'Verbose' or 'Plain', giving either very
1053 1051 detailed or normal tracebacks respectively. The color_scheme keyword can
1054 1052 be one of 'NoColor', 'Linux' (default) or 'LightBG'. These are the same
1055 1053 options which can be set in IPython with -colors and -xmode.
1056 1054
1057 1055 This will give any of your programs detailed, colored tracebacks with
1058 1056 automatic invocation of pdb.
1059 1057
1060 1058
1061 1059 Extensions for syntax processing
1062 1060 ================================
1063 1061
1064 1062 This isn't for the faint of heart, because the potential for breaking
1065 1063 things is quite high. But it can be a very powerful and useful feature.
1066 1064 In a nutshell, you can redefine the way IPython processes the user input
1067 1065 line to accept new, special extensions to the syntax without needing to
1068 1066 change any of IPython's own code.
1069 1067
1070 1068 In the IPython/extensions directory you will find some examples
1071 1069 supplied, which we will briefly describe now. These can be used 'as is'
1072 1070 (and both provide very useful functionality), or you can use them as a
1073 1071 starting point for writing your own extensions.
1074 1072
1075 1073
1076 1074 Pasting of code starting with '>>> ' or '... '
1077 1075 ----------------------------------------------
1078 1076
1079 1077 In the python tutorial it is common to find code examples which have
1080 1078 been taken from real python sessions. The problem with those is that all
1081 1079 the lines begin with either '>>> ' or '... ', which makes it impossible
1082 1080 to paste them all at once. One must instead do a line by line manual
1083 1081 copying, carefully removing the leading extraneous characters.
1084 1082
1085 1083 This extension identifies those starting characters and removes them
1086 1084 from the input automatically, so that one can paste multi-line examples
1087 1085 directly into IPython, saving a lot of time. Please look at the file
1088 1086 InterpreterPasteInput.py in the IPython/extensions directory for details
1089 1087 on how this is done.
1090 1088
1091 1089 IPython comes with a special profile enabling this feature, called
1092 1090 tutorial. Simply start IPython via 'ipython -p tutorial' and the feature
1093 1091 will be available. In a normal IPython session you can activate the
1094 1092 feature by importing the corresponding module with:
1095 1093 In [1]: import IPython.extensions.InterpreterPasteInput
1096 1094
1097 1095 The following is a 'screenshot' of how things work when this extension
1098 1096 is on, copying an example from the standard tutorial::
1099 1097
1100 1098 IPython profile: tutorial
1101 1099
1102 1100 *** Pasting of code with ">>>" or "..." has been enabled.
1103 1101
1104 1102 In [1]: >>> def fib2(n): # return Fibonacci series up to n
1105 1103 ...: ... """Return a list containing the Fibonacci series up to
1106 1104 n."""
1107 1105 ...: ... result = []
1108 1106 ...: ... a, b = 0, 1
1109 1107 ...: ... while b < n:
1110 1108 ...: ... result.append(b) # see below
1111 1109 ...: ... a, b = b, a+b
1112 1110 ...: ... return result
1113 1111 ...:
1114 1112
1115 1113 In [2]: fib2(10)
1116 1114 Out[2]: [1, 1, 2, 3, 5, 8]
1117 1115
1118 1116 Note that as currently written, this extension does not recognize
1119 1117 IPython's prompts for pasting. Those are more complicated, since the
1120 1118 user can change them very easily, they involve numbers and can vary in
1121 1119 length. One could however extract all the relevant information from the
1122 1120 IPython instance and build an appropriate regular expression. This is
1123 1121 left as an exercise for the reader.
1124 1122
1125 1123 .. _gui_support:
1126 1124
1127 1125 GUI event loop support
1128 1126 ======================
1129 1127
1130 1128 .. versionadded:: 0.11
1131 1129 The ``%gui`` magic and :mod:`IPython.lib.inputhook`.
1132 1130
1133 1131 IPython has excellent support for working interactively with Graphical User
1134 1132 Interface (GUI) toolkits, such as wxPython, PyQt4, PyGTK and Tk. This is
1135 1133 implemented using Python's builtin ``PyOSInputHook`` hook. This implementation
1136 1134 is extremely robust compared to our previous thread-based version. The
1137 1135 advantages of this are:
1138 1136
1139 1137 * GUIs can be enabled and disabled dynamically at runtime.
1140 1138 * The active GUI can be switched dynamically at runtime.
1141 1139 * In some cases, multiple GUIs can run simultaneously with no problems.
1142 1140 * There is a developer API in :mod:`IPython.lib.inputhook` for customizing
1143 1141 all of these things.
1144 1142
1145 1143 For users, enabling GUI event loop integration is simple. You simple use the
1146 1144 ``%gui`` magic as follows::
1147 1145
1148 1146 %gui [GUINAME]
1149 1147
1150 1148 With no arguments, ``%gui`` removes all GUI support. Valid ``GUINAME``
1151 1149 arguments are ``wx``, ``qt4``, ``gtk`` and ``tk``.
1152 1150
1153 1151 Thus, to use wxPython interactively and create a running :class:`wx.App`
1154 1152 object, do::
1155 1153
1156 1154 %gui wx
1157 1155
1158 1156 For information on IPython's Matplotlib integration (and the ``pylab`` mode)
1159 1157 see :ref:`this section <matplotlib_support>`.
1160 1158
1161 1159 For developers that want to use IPython's GUI event loop integration in
1162 1160 the form of a library, these capabilities are exposed in library form
1163 1161 in the :mod:`IPython.lib.inputhook`. Interested developers should see the
1164 1162 module docstrings for more information, but there are a few points that
1165 1163 should be mentioned here.
1166 1164
1167 1165 First, the ``PyOSInputHook`` approach only works in command line settings
1168 1166 where readline is activated.
1169 1167
1170 1168 Second, when using the ``PyOSInputHook`` approach, a GUI application should
1171 1169 *not* start its event loop. Instead all of this is handled by the
1172 1170 ``PyOSInputHook``. This means that applications that are meant to be used both
1173 1171 in IPython and as standalone apps need to have special code to detects how the
1174 1172 application is being run. We highly recommend using IPython's
1175 1173 :func:`enable_foo` functions for this. Here is a simple example that shows the
1176 1174 recommended code that should be at the bottom of a wxPython using GUI
1177 1175 application::
1178 1176
1179 1177 try:
1180 1178 from IPython.lib.inputhook import enable_wx
1181 1179 enable_wx(app)
1182 1180 except ImportError:
1183 1181 app.MainLoop()
1184 1182
1185 1183 This pattern should be used instead of the simple ``app.MainLoop()`` code
1186 1184 that a standalone wxPython application would have.
1187 1185
1188 1186 Third, unlike previous versions of IPython, we no longer "hijack" (replace
1189 1187 them with no-ops) the event loops. This is done to allow applications that
1190 1188 actually need to run the real event loops to do so. This is often needed to
1191 1189 process pending events at critical points.
1192 1190
1193 1191 Finally, we also have a number of examples in our source directory
1194 1192 :file:`docs/examples/lib` that demonstrate these capabilities.
1195 1193
1196 1194 PyQt and PySide
1197 1195 ---------------
1198 1196
1199 1197 .. attempt at explanation of the complete mess that is Qt support
1200 1198
1201 1199 When you use ``--gui=qt`` or ``--pylab=qt``, IPython can work with either
1202 1200 PyQt4 or PySide. There are three options for configuration here, because
1203 1201 PyQt4 has two APIs for QString and QVariant - v1, which is the default on
1204 1202 Python 2, and the more natural v2, which is the only API supported by PySide.
1205 1203 v2 is also the default for PyQt4 on Python 3. IPython's code for the QtConsole
1206 1204 uses v2, but you can still use any interface in your code, since the
1207 1205 Qt frontend is in a different process.
1208 1206
1209 1207 The default will be to import PyQt4 without configuration of the APIs, thus
1210 1208 matching what most applications would expect. It will fall back of PySide if
1211 1209 PyQt4 is unavailable.
1212 1210
1213 1211 If specified, IPython will respect the environment variable ``QT_API`` used
1214 1212 by ETS. ETS 4.0 also works with both PyQt4 and PySide, but it requires
1215 1213 PyQt4 to use its v2 API. So if ``QT_API=pyside`` PySide will be used,
1216 1214 and if ``QT_API=pyqt`` then PyQt4 will be used *with the v2 API* for
1217 1215 QString and QVariant, so ETS codes like MayaVi will also work with IPython.
1218 1216
1219 1217 If you launch IPython in pylab mode with ``ipython --pylab=qt``, then IPython
1220 1218 will ask matplotlib which Qt library to use (only if QT_API is *not set*), via
1221 1219 the 'backend.qt4' rcParam. If matplotlib is version 1.0.1 or older, then
1222 1220 IPython will always use PyQt4 without setting the v2 APIs, since neither v2
1223 1221 PyQt nor PySide work.
1224 1222
1225 1223 .. warning::
1226 1224
1227 1225 Note that this means for ETS 4 to work with PyQt4, ``QT_API`` *must* be set
1228 1226 to work with IPython's qt integration, because otherwise PyQt4 will be
1229 1227 loaded in an incompatible mode.
1230 1228
1231 1229 It also means that you must *not* have ``QT_API`` set if you want to
1232 1230 use ``--gui=qt`` with code that requires PyQt4 API v1.
1233 1231
1234 1232
1235 1233 .. _matplotlib_support:
1236 1234
1237 1235 Plotting with matplotlib
1238 1236 ========================
1239 1237
1240 1238 `Matplotlib`_ provides high quality 2D and 3D plotting for Python. Matplotlib
1241 1239 can produce plots on screen using a variety of GUI toolkits, including Tk,
1242 1240 PyGTK, PyQt4 and wxPython. It also provides a number of commands useful for
1243 1241 scientific computing, all with a syntax compatible with that of the popular
1244 1242 Matlab program.
1245 1243
1246 1244 To start IPython with matplotlib support, use the ``--pylab`` switch. If no
1247 1245 arguments are given, IPython will automatically detect your choice of
1248 1246 matplotlib backend. You can also request a specific backend with
1249 1247 ``--pylab=backend``, where ``backend`` must be one of: 'tk', 'qt', 'wx', 'gtk',
1250 1248 'osx'.
1251 1249
1252 1250 .. _Matplotlib: http://matplotlib.sourceforge.net
1253 1251
1254 1252 .. _interactive_demos:
1255 1253
1256 1254 Interactive demos with IPython
1257 1255 ==============================
1258 1256
1259 1257 IPython ships with a basic system for running scripts interactively in
1260 1258 sections, useful when presenting code to audiences. A few tags embedded
1261 1259 in comments (so that the script remains valid Python code) divide a file
1262 1260 into separate blocks, and the demo can be run one block at a time, with
1263 1261 IPython printing (with syntax highlighting) the block before executing
1264 1262 it, and returning to the interactive prompt after each block. The
1265 1263 interactive namespace is updated after each block is run with the
1266 1264 contents of the demo's namespace.
1267 1265
1268 1266 This allows you to show a piece of code, run it and then execute
1269 1267 interactively commands based on the variables just created. Once you
1270 1268 want to continue, you simply execute the next block of the demo. The
1271 1269 following listing shows the markup necessary for dividing a script into
1272 1270 sections for execution as a demo:
1273 1271
1274 1272 .. literalinclude:: ../../examples/lib/example-demo.py
1275 1273 :language: python
1276 1274
1277
1278 1275 In order to run a file as a demo, you must first make a Demo object out
1279 1276 of it. If the file is named myscript.py, the following code will make a
1280 1277 demo::
1281 1278
1282 1279 from IPython.lib.demo import Demo
1283 1280
1284 1281 mydemo = Demo('myscript.py')
1285 1282
1286 1283 This creates the mydemo object, whose blocks you run one at a time by
1287 1284 simply calling the object with no arguments. If you have autocall active
1288 1285 in IPython (the default), all you need to do is type::
1289 1286
1290 1287 mydemo
1291 1288
1292 1289 and IPython will call it, executing each block. Demo objects can be
1293 1290 restarted, you can move forward or back skipping blocks, re-execute the
1294 1291 last block, etc. Simply use the Tab key on a demo object to see its
1295 1292 methods, and call '?' on them to see their docstrings for more usage
1296 1293 details. In addition, the demo module itself contains a comprehensive
1297 1294 docstring, which you can access via::
1298 1295
1299 1296 from IPython.lib import demo
1300 1297
1301 1298 demo?
1302 1299
1303 1300 Limitations: It is important to note that these demos are limited to
1304 1301 fairly simple uses. In particular, you can not put division marks in
1305 1302 indented code (loops, if statements, function definitions, etc.)
1306 1303 Supporting something like this would basically require tracking the
1307 1304 internal execution state of the Python interpreter, so only top-level
1308 1305 divisions are allowed. If you want to be able to open an IPython
1309 1306 instance at an arbitrary point in a program, you can use IPython's
1310 1307 embedding facilities, see :func:`IPython.embed` for details.
1311 1308
@@ -1,748 +1,752 b''
1 1 =============
2 2 0.11 Series
3 3 =============
4 4
5 5 Release 0.11
6 6 ============
7 7
8 8 IPython 0.11 is a *major* overhaul of IPython, two years in the making. Most
9 9 of the code base has been rewritten or at least reorganized, breaking backward
10 10 compatibility with several APIs in previous versions. It is the first major
11 11 release in two years, and probably the most significant change to IPython since
12 12 its inception. We plan to have a relatively quick succession of releases, as
13 13 people discover new bugs and regressions. Once we iron out any significant
14 14 bugs in this process and settle down the new APIs, this series will become
15 15 IPython 1.0. We encourage feedback now on the core APIs, which we hope to
16 16 maintain stable during the 1.0 series.
17 17
18 18 Since the internal APIs have changed so much, projects using IPython as a
19 19 library (as opposed to end-users of the application) are the most likely to
20 20 encounter regressions or changes that break their existing use patterns. We
21 21 will make every effort to provide updated versions of the APIs to facilitate
22 22 the transition, and we encourage you to contact us on the `development mailing
23 23 list`__ with questions and feedback.
24 24
25 25 .. __: http://mail.scipy.org/mailman/listinfo/ipython-dev
26 26
27 27 Chris Fonnesbeck recently wrote an `excellent post`__ that highlights some of
28 28 our major new features, with examples and screenshots. We encourage you to
29 29 read it as it provides an illustrated, high-level overview complementing the
30 30 detailed feature breakdown in this document.
31 31
32 32 .. __: http://stronginference.com/weblog/2011/7/15/innovations-in-ipython.html
33 33
34 34 A quick summary of the major changes (see below for details):
35 35
36 36 * **Standalone Qt console**: a new rich console has been added to IPython,
37 37 started with `ipython qtconsole`. In this application we have tried to
38 38 retain the feel of a terminal for fast and efficient workflows, while adding
39 39 many features that a plain text terminal simply can not support, such as
40 40 inline figures, full multiline editing with syntax highlighting, tooltips for
41 41 function calls and much more. This development was sponsored by `Enthought
42 42 Inc.`__. See :ref:`below <qtconsole_011>` for details.
43 43
44 44 .. __: http://enthought.com
45 45
46 46 * **High-level parallel computing with ZeroMQ**. Using the same architecture
47 47 that our Qt console is based on, we have completely rewritten our high-level
48 48 parallel computing machinery that in prior versions used the Twisted
49 49 networking framework. While this change will require users to update their
50 50 codes, the improvements in performance, memory control and internal
51 51 consistency across our codebase convinced us it was a price worth paying. We
52 52 have tried to explain how to best proceed with this update, and will be happy
53 53 to answer questions that may arise. A full tutorial describing these
54 54 features `was presented at SciPy'11`__.
55 55
56 56 .. __: http://minrk.github.com/scipy-tutorial-2011
57 57
58 58 * **New model for GUI/plotting support in the terminal**. Now instead of the
59 59 various `-Xthread` flags we had before, GUI support is provided without the
60 60 use of any threads, by directly integrating GUI event loops with Python's
61 61 `PyOS_InputHook` API. A new command-line flag `--gui` controls GUI support,
62 62 and it can also be enabled after IPython startup via the new `%gui` magic.
63 63 This requires some changes if you want to execute GUI-using scripts inside
64 64 IPython, see :ref:`the GUI support section <gui_support>` for more details.
65 65
66 * **Integration into Microsoft Visual Studio**. Thanks to the work of the
67 Microsoft `Python Tools for Visual Studio`__ team, this version of IPython
68 has been integrated into Microsoft Visual Studio's Python tools open source
69 plug-in. `Details below`_
70
71 .. __: http://pytools.codeplex.com
72 .. _details below: ms_visual_studio_011_
73
74 66 * **A two-process architecture.** The Qt console is the first example of using
75 67 a new model that splits IPython between a kernel process where code is
76 68 executed and a client that handles user interaction. We plan on also
77 69 providing terminal and web-browser based clients using this infrastructure in
78 70 future releases. This model allows multiple clients to interact with an
79 71 IPython process through a well-documented protocol using the ZeroMQ
80 72 networking library.
81 73
82 74 * **Refactoring.** the entire codebase has been refactored, in order to make it
83 75 more modular and easier to contribute to. IPython has traditionally been a
84 76 hard project to participate because the old codebase was very monolithic. We
85 77 hope this (ongoing) restructuring will make it easier for new developers to
86 78 join us.
87 79
80 * **Vim integration**. Vim can be configured to seamlessly control an IPython
81 kernel, see the files in :file:`docs/examples/vim` for the full details.
82 This work was done by Paul Ivanov, who prepared a nice `video
83 demonstration`__ of the features it provides.
84
85 .. __: http://pirsquared.org/blog/2011/07/28/vim-ipython/
86
87 * **Integration into Microsoft Visual Studio**. Thanks to the work of the
88 Microsoft `Python Tools for Visual Studio`__ team, this version of IPython
89 has been integrated into Microsoft Visual Studio's Python tools open source
90 plug-in. `Details below`_
91
92 .. __: http://pytools.codeplex.com
93 .. _details below: ms_visual_studio_011_
94
88 95 * **Improved unicode support**. We closed many bugs related to unicode input.
89 96
90 97 * **Python 3**. IPython now runs on Python 3.x. See :ref:`python3_011` for
91 98 details.
92 99
93 100 * **New profile model**. Profiles are now directories that contain all relevant
94 101 infromation for that session, and thus better isolate IPython use-cases.
95 102
96 103 * **SQLite storage for history**. All history is now stored in a SQLite
97 104 database, providing support for multiple simultaneous sessions that won't
98 105 clobber each other as well as the ability to perform queries on all stored
99 106 data.
100 107
101 108 * **New configuration system**. All parts of IPython are now configured via a
102 109 mechanism inspired by the Enthought Traits library. Any configurable element
103 110 can have its attributes set either via files that now use real Python syntax
104 111 or from the command-line.
105 112
106 * **Vim integration**. Vim can be configured to seamlessly control an IPython
107 kernel, see the files in :file:`docs/examples/vim` for the full details.
108 This work was done by Paul Ivanov, who prepared a nice `video
109 demonstration`__ of the features it provides.
110
111 .. __: http://pirsquared.org/blog/2011/07/28/vim-ipython/
112 113
113 114 Authors and support
114 115 -------------------
115 116
116 117 Over 60 separate authors have contributed to this release, see :ref:`below
117 118 <credits_011>` for a full list. In particular, we want to highlight the
118 119 extremely active participation of two new core team members: Evan Patterson
119 120 implemented the Qt console, and Thomas Kluyver started with our Python 3 port
120 121 and by now has made major contributions to just about every area of IPython.
121 122
122 123 We are also grateful for the support we have received during this development
123 124 cycle from several institutions:
124 125
125 126 - `Enthought Inc`__ funded the development of our new Qt console, an effort that
126 127 required developing major pieces of underlying infrastructure, which now
127 128 power not only the Qt console but also our new parallel machinery. We'd like
128 129 to thank Eric Jones and Travis Oliphant for their support, as well as Ilan
129 130 Schnell for his tireless work integrating and testing IPython in the
130 131 `Enthought Python Distribution`_.
131 132
132 133 .. __: http://enthought.com
133 134 .. _Enthought Python Distribution: http://www.enthought.com/products/epd.php
134 135
135 136 - Nipy/NIH: funding via the `NiPy project`__ (NIH grant 5R01MH081909-02) helped
136 137 us jumpstart the development of this series by restructuring the entire
137 138 codebase two years ago in a way that would make modular development and
138 139 testing more approachable. Without this initial groundwork, all the new
139 140 features we have added would have been impossible to develop.
140 141
141 142 .. __: http://nipy.org
142 143
143 144 - Sage/NSF: funding via the grant `Sage: Unifying Mathematical Software for
144 145 Scientists, Engineers, and Mathematicians`__ (NSF grant DMS-1015114)
145 146 supported a meeting in spring 2011 of several of the core IPython developers
146 147 where major progress was made integrating the last key pieces leading to this
147 148 release.
148 149
149 150 .. __: http://modular.math.washington.edu/grants/compmath09
150 151
151 152 - Microsoft's team working on `Python Tools for Visual Studio`__ developed the
152 153 integraton of IPython into the Python plugin for Visual Studio 2010.
153 154
154 155 .. __: http://pytools.codeplex.com
155 156
156 157 - Google Summer of Code: in 2010, we had two students developing prototypes of
157 158 the new machinery that is now maturing in this release: `Omar Zapata`_ and
158 159 `Gerardo Gutiérrez`_.
159 160
160 161 .. _Omar Zapata: http://ipythonzmq.blogspot.com/2010/08/ipython-zmq-status.html
161 162 .. _Gerardo Gutiérrez: http://ipythonqt.blogspot.com/2010/04/ipython-qt-interface-gsoc-2010-proposal.html>
162 163
163 164
164 165 Development summary
165 166 -------------------
166 167
167 168 In April 2010, after `one breakage too many with bzr`__, we decided to move our
168 169 entire development process to Git and Github.com. This has proven to be one of
169 170 the best decisions in the project's history, as the combination of git and
170 171 github have made us far, far more productive than we could be with our previous
171 172 tools. We first converted our bzr repo to a git one without losing history,
172 173 and a few weeks later ported all open Launchpad bugs to github issues with
173 174 their comments mostly intact (modulo some formatting changes). This ensured a
174 175 smooth transition where no development history or submitted bugs were lost.
175 176
176 177 .. __: http://mail.scipy.org/pipermail/ipython-dev/2010-April/005944.html
177 178
178 179 These simple statistics show how much work has been done on the new release, by
179 180 comparing the current code to the last point it had in common with the 0.10
180 181 series. A huge diff and over 2000 commits make up this development::
181 182
182 183 git diff $(git merge-base 0.10.2 HEAD) | wc -l
183 184 287676
184 185
185 186 git log $(git merge-base 0.10.2 HEAD) --oneline | wc -l
186 187 2046
187 188
188 189 Since our move to github, 510 issues were closed, 225 of which were pull
189 190 requests and 285 regular issues (see :ref:`below <issues_list_011>` for a full
190 191 list). Github's pull requests are a fantastic mechanism for reviewing code and
191 192 building a shared ownership of the project, and we are making enthusiastic use
192 193 of it.
193 194
194 Note: this undercounts the number of issues closed in this development cycle,
195 since we only moved to github for issue tracking in May 2010, but we have no
196 way of collecting statistics on the number of issues closed in the old
197 Launchpad bug tracker prior to that.
195 .. Note::
198 196
197 This undercounts the number of issues closed in this development cycle,
198 since we only moved to github for issue tracking in May 2010, but we have no
199 way of collecting statistics on the number of issues closed in the old
200 Launchpad bug tracker prior to that.
201
202
199 203 .. _qtconsole_011:
200 204
201 205 Qt Console
202 206 ----------
203 207
204 208 IPython now ships with a Qt application that feels very much like a terminal,
205 209 but is in fact a rich GUI that runs an IPython client but supports inline
206 210 figures, saving sessions to PDF and HTML, multiline editing with syntax
207 211 highlighting, graphical calltips and much more:
208 212
209 213 .. figure:: ../_static/qtconsole.png
210 214 :width: 400px
211 215 :alt: IPython Qt console with embedded plots
212 216 :align: center
213 217 :target: ../_static/qtconsole.png
214 218
215 219 The Qt console for IPython, using inline matplotlib plots.
216 220
217 221 We hope that many projects will embed this widget, which we've kept
218 222 deliberately very lightweight, into their own environments. In the future we
219 223 may also offer a slightly more featureful application (with menus and other GUI
220 224 elements), but we remain committed to always shipping this easy to embed
221 225 widget.
222 226
223 227 See the :ref:`Qt console section <qtconsole>` of the docs for a detailed
224 228 description of the console's features and use.
225 229
226 230
227 231 High-level parallel computing with ZeroMQ
228 232 -----------------------------------------
229 233
230 234 We have completely rewritten the Twisted-based code for high-level parallel
231 235 computing to work atop our new ZeroMQ architecture. While we realize this will
232 236 break compatibility for a number of users, we hope to make the transition as
233 237 easy as possible with our docs, and we are convinced the change is worth it.
234 238 ZeroMQ provides us with much tighter control over memory, higher performance,
235 239 and its communications are impervious to the Python Global Interpreter Lock
236 240 because they take place in a system-level C++ thread. The impact of the GIL in
237 241 our previous code was something we could simply not work around, given that
238 242 Twisted is itself a Python library. So while Twisted is a very capable
239 243 framework, we think ZeroMQ fits our needs much better and we hope you will find
240 244 the change to be a significant improvement in the long run.
241 245
242 246 Our manual contains :ref:`a full description of how to use IPython for parallel
243 247 computing <parallel_overview>`, and the `tutorial`__ presented by Min
244 248 Ragan-Kelley at the SciPy 2011 conference provides a hands-on complement to the
245 249 reference docs.
246 250
247 251 .. __: http://minrk.github.com/scipy-tutorial-2011
248 252
249 253
250 254 Refactoring
251 255 -----------
252 256
253 As of the 0.11 version of IPython, a signifiant portion of the core has been
254 refactored. This refactoring is founded on a number of new abstractions.
255 The main new classes that implement these abstractions are:
257 As of this release, a signifiant portion of IPython has been refactored. This
258 refactoring is founded on a number of new abstractions. The main new classes
259 that implement these abstractions are:
256 260
257 261 * :class:`IPython.utils.traitlets.HasTraits`.
258 262 * :class:`IPython.config.configurable.Configurable`.
259 263 * :class:`IPython.config.application.Application`.
260 264 * :class:`IPython.config.loader.ConfigLoader`.
261 265 * :class:`IPython.config.loader.Config`
262 266
263 267 We are still in the process of writing developer focused documentation about
264 268 these classes, but for now our :ref:`configuration documentation
265 269 <config_overview>` contains a high level overview of the concepts that these
266 270 classes express.
267 271
268 272 The biggest user-visible change is likely the move to using the config system to
269 273 determine the command-line arguments for IPython applications. The benefit of
270 274 this is that *all* configurable values in IPython are exposed on the
271 275 command-line, but the syntax for specifying values has changed. The gist is that
272 276 assigning values is pure Python assignment, so there is always an '=', and never
273 277 a leading '-', nor a space separating key from value. Flags exist, to set
274 278 multiple values or boolean flags, and these are always prefixed with '--', and
275 279 never take arguments.
276 280
277 ZMQ architecture
278 ----------------
281 ZeroMQ architecture
282 -------------------
279 283
280 284 There is a new GUI framework for IPython, based on a client-server model in
281 285 which multiple clients can communicate with one IPython kernel, using the
282 286 ZeroMQ messaging framework. There is already a Qt console client, which can
283 287 be started by calling ``ipython qtconsole``. The protocol is :ref:`documented
284 288 <messaging>`.
285 289
286 290 The parallel computing framework has also been rewritten using ZMQ. The
287 291 protocol is described :ref:`here <parallel_messages>`, and the code is in the
288 292 new :mod:`IPython.parallel` module.
289 293
290 294 .. _python3_011:
291 295
292 296 Python 3 support
293 297 ----------------
294 298
295 299 A Python 3 version of IPython has been prepared. For the time being, this is
296 300 maintained separately and updated from the main codebase. Its code can be found
297 301 `here <https://github.com/ipython/ipython-py3k>`_. The parallel computing
298 302 components are not perfect on Python3, but most functionality appears to be
299 303 working. As this work is evolving quickly, the best place to find updated
300 304 information about it is our `Python 3 wiki page`__.
301 305
302 306 .. __: http://wiki.ipython.org/index.php?title=Python_3
303 307
304 308
305 309 Unicode
306 310 -------
307 311
308 312 Entering non-ascii characters in unicode literals (``u"€ø"``) now works
309 313 properly on all platforms. However, entering these in byte/string literals
310 314 (``"€ø"``) will not work as expected on Windows (or any platform where the
311 315 terminal encoding is not UTF-8, as it typically is for Linux & Mac OS X). You
312 316 can use escape sequences (``"\xe9\x82"``) to get bytes above 128, or use
313 317 unicode literals and encode them. This is a limitation of Python 2 which we
314 318 cannot easily work around.
315 319
316 320 .. _ms_visual_studio_011:
317 321
318 322 Integration with Microsoft Visual Studio
319 323 ----------------------------------------
320 324
321 325 IPython can be used as the interactive shell in the `Python plugin for
322 326 Microsoft Visual Studio`__, as seen here:
323 327
324 328 .. figure:: ../_static/ms_visual_studio.png
325 329 :width: 500px
326 330 :alt: IPython console embedded in Microsoft Visual Studio.
327 331 :align: center
328 332 :target: ../_static/ms_visual_studio.png
329 333
330 334 IPython console embedded in Microsoft Visual Studio.
331 335
332 336 The Microsoft team developing this currently has a release candidate out using
333 337 IPython 0.11. We will continue to collaborate with them to ensure that as they
334 approach full release time, the integration with IPython is as smooth as
335 possible. We'd like to thank Dino Viehland and Shahrokh Mortazavi for the work
336 they have done towards this feature, as well as Wenming Ye for his support of
337 our WinHPC features.
338 approach their final release date, the integration with IPython remains smooth.
339 We'd like to thank Dino Viehland and Shahrokh Mortazavi for the work they have
340 done towards this feature, as well as Wenming Ye for his support of our WinHPC
341 capabilities.
338 342
339 343 .. __: http://pytools.codeplex.com
340 344
341 345
342 346 Additional new features
343 347 -----------------------
344 348
345 349 * Added ``Bytes`` traitlet, removing ``Str``. All 'string' traitlets should
346 350 either be ``Unicode`` if a real string, or ``Bytes`` if a C-string. This
347 351 removes ambiguity and helps the Python 3 transition.
348 352
349 353 * New magic ``%loadpy`` loads a python file from disk or web URL into
350 354 the current input buffer.
351 355
352 356 * New magic ``%pastebin`` for sharing code via the 'Lodge it' pastebin.
353 357
354 358 * New magic ``%precision`` for controlling float and numpy pretty printing.
355 359
356 360 * IPython applications initiate logging, so any object can gain access to
357 361 a the logger of the currently running Application with:
358 362
359 363 .. sourcecode:: python
360 364
361 365 from IPython.config.application import Application
362 366 logger = Application.instance().log
363 367
364 368 * You can now get help on an object halfway through typing a command. For
365 369 instance, typing ``a = zip?`` shows the details of :func:`zip`. It also
366 370 leaves the command at the next prompt so you can carry on with it.
367 371
368 372 * The input history is now written to an SQLite database. The API for
369 373 retrieving items from the history has also been redesigned.
370 374
371 375 * The :mod:`IPython.extensions.pretty` extension has been moved out of
372 376 quarantine and fully updated to the new extension API.
373 377
374 378 * New magics for loading/unloading/reloading extensions have been added:
375 379 ``%load_ext``, ``%unload_ext`` and ``%reload_ext``.
376 380
377 381 * The configuration system and configuration files are brand new. See the
378 382 configuration system :ref:`documentation <config_index>` for more details.
379 383
380 384 * The :class:`~IPython.core.interactiveshell.InteractiveShell` class is now a
381 385 :class:`~IPython.config.configurable.Configurable` subclass and has traitlets
382 386 that determine the defaults and runtime environment. The ``__init__`` method
383 387 has also been refactored so this class can be instantiated and run without
384 388 the old :mod:`ipmaker` module.
385 389
386 390 * The methods of :class:`~IPython.core.interactiveshell.InteractiveShell` have
387 391 been organized into sections to make it easier to turn more sections
388 392 of functionality into components.
389 393
390 394 * The embedded shell has been refactored into a truly standalone subclass of
391 395 :class:`InteractiveShell` called :class:`InteractiveShellEmbed`. All
392 396 embedding logic has been taken out of the base class and put into the
393 397 embedded subclass.
394 398
395 399 * Added methods of :class:`~IPython.core.interactiveshell.InteractiveShell` to
396 400 help it cleanup after itself. The :meth:`cleanup` method controls this. We
397 401 couldn't do this in :meth:`__del__` because we have cycles in our object
398 402 graph that prevent it from being called.
399 403
400 404 * Created a new module :mod:`IPython.utils.importstring` for resolving
401 405 strings like ``foo.bar.Bar`` to the actual class.
402 406
403 407 * Completely refactored the :mod:`IPython.core.prefilter` module into
404 408 :class:`~IPython.config.configurable.Configurable` subclasses. Added a new
405 409 layer into the prefilter system, called "transformations" that all new
406 410 prefilter logic should use (rather than the older "checker/handler"
407 411 approach).
408 412
409 413 * Aliases are now components (:mod:`IPython.core.alias`).
410 414
411 415 * New top level :func:`~IPython.frontend.terminal.embed.embed` function that can
412 416 be called to embed IPython at any place in user's code. On the first call it
413 417 will create an :class:`~IPython.frontend.terminal.embed.InteractiveShellEmbed`
414 418 instance and call it. In later calls, it just calls the previously created
415 419 :class:`~IPython.frontend.terminal.embed.InteractiveShellEmbed`.
416 420
417 421 * Created a configuration system (:mod:`IPython.config.configurable`) that is
418 422 based on :mod:`IPython.utils.traitlets`. Configurables are arranged into a
419 423 runtime containment tree (not inheritance) that i) automatically propagates
420 424 configuration information and ii) allows singletons to discover each other in
421 425 a loosely coupled manner. In the future all parts of IPython will be
422 426 subclasses of :class:`~IPython.config.configurable.Configurable`. All IPython
423 427 developers should become familiar with the config system.
424 428
425 429 * Created a new :class:`~IPython.config.loader.Config` for holding
426 430 configuration information. This is a dict like class with a few extras: i)
427 431 it supports attribute style access, ii) it has a merge function that merges
428 432 two :class:`~IPython.config.loader.Config` instances recursively and iii) it
429 433 will automatically create sub-:class:`~IPython.config.loader.Config`
430 434 instances for attributes that start with an uppercase character.
431 435
432 436 * Created new configuration loaders in :mod:`IPython.config.loader`. These
433 437 loaders provide a unified loading interface for all configuration
434 438 information including command line arguments and configuration files. We
435 439 have two default implementations based on :mod:`argparse` and plain python
436 440 files. These are used to implement the new configuration system.
437 441
438 442 * Created a top-level :class:`Application` class in
439 443 :mod:`IPython.core.application` that is designed to encapsulate the starting
440 444 of any basic Python program. An application loads and merges all the
441 445 configuration objects, constructs the main application, configures and
442 446 initiates logging, and creates and configures any :class:`Configurable`
443 447 instances and then starts the application running. An extended
444 448 :class:`BaseIPythonApplication` class adds logic for handling the
445 449 IPython directory as well as profiles, and all IPython entry points
446 450 extend it.
447 451
448 452 * The :class:`Type` and :class:`Instance` traitlets now handle classes given
449 453 as strings, like ``foo.bar.Bar``. This is needed for forward declarations.
450 454 But, this was implemented in a careful way so that string to class
451 455 resolution is done at a single point, when the parent
452 456 :class:`~IPython.utils.traitlets.HasTraitlets` is instantiated.
453 457
454 458 * :mod:`IPython.utils.ipstruct` has been refactored to be a subclass of
455 459 dict. It also now has full docstrings and doctests.
456 460
457 461 * Created a Traits like implementation in :mod:`IPython.utils.traitlets`. This
458 462 is a pure Python, lightweight version of a library that is similar to
459 463 Enthought's Traits project, but has no dependencies on Enthought's code. We
460 464 are using this for validation, defaults and notification in our new component
461 465 system. Although it is not 100% API compatible with Enthought's Traits, we
462 466 plan on moving in this direction so that eventually our implementation could
463 467 be replaced by a (yet to exist) pure Python version of Enthought Traits.
464 468
465 469 * Added a new module :mod:`IPython.lib.inputhook` to manage the integration
466 470 with GUI event loops using `PyOS_InputHook`. See the docstrings in this
467 471 module or the main IPython docs for details.
468 472
469 473 * For users, GUI event loop integration is now handled through the new
470 474 :command:`%gui` magic command. Type ``%gui?`` at an IPython prompt for
471 475 documentation.
472 476
473 477 * For developers :mod:`IPython.lib.inputhook` provides a simple interface
474 478 for managing the event loops in their interactive GUI applications.
475 479 Examples can be found in our :file:`docs/examples/lib` directory.
476 480
477 481 Backwards incompatible changes
478 482 ------------------------------
479 483
480 484 * The Twisted-based :mod:`IPython.kernel` has been removed, and completely
481 485 rewritten as :mod:`IPython.parallel`, using ZeroMQ.
482 486
483 487 * Profiles are now directories. Instead of a profile being a single config file,
484 488 profiles are now self-contained directories. By default, profiles get their
485 489 own IPython history, log files, and everything. To create a new profile, do
486 490 ``ipython profile create <name>``.
487 491
488 492 * All IPython applications have been rewritten to use
489 493 :class:`~IPython.config.loader.KeyValueConfigLoader`. This means that
490 494 command-line options have changed. Now, all configurable values are accessible
491 495 from the command-line with the same syntax as in a configuration file.
492 496
493 497 * The command line options ``-wthread``, ``-qthread`` and
494 498 ``-gthread`` have been removed. Use ``--gui=wx``, ``--gui=qt``, ``--gui=gtk``
495 499 instead.
496 500
497 501 * The extension loading functions have been renamed to
498 502 :func:`load_ipython_extension` and :func:`unload_ipython_extension`.
499 503
500 504 * :class:`~IPython.core.interactiveshell.InteractiveShell` no longer takes an
501 505 ``embedded`` argument. Instead just use the
502 506 :class:`~IPython.core.interactiveshell.InteractiveShellEmbed` class.
503 507
504 508 * ``__IPYTHON__`` is no longer injected into ``__builtin__``.
505 509
506 510 * :meth:`Struct.__init__` no longer takes `None` as its first argument. It
507 511 must be a :class:`dict` or :class:`Struct`.
508 512
509 513 * :meth:`~IPython.core.interactiveshell.InteractiveShell.ipmagic` has been
510 514 renamed :meth:`~IPython.core.interactiveshell.InteractiveShell.magic.`
511 515
512 516 * The functions :func:`ipmagic` and :func:`ipalias` have been removed from
513 517 :mod:`__builtins__`.
514 518
515 519 * The references to the global
516 520 :class:`~IPython.core.interactivehell.InteractiveShell` instance (``_ip``, and
517 521 ``__IP``) have been removed from the user's namespace. They are replaced by a
518 522 new function called :func:`get_ipython` that returns the current
519 523 :class:`~IPython.core.interactiveshell.InteractiveShell` instance. This
520 524 function is injected into the user's namespace and is now the main way of
521 525 accessing the running IPython.
522 526
523 527 * Old style configuration files :file:`ipythonrc` and :file:`ipy_user_conf.py`
524 528 are no longer supported. Users should migrate there configuration files to
525 529 the new format described :ref:`here <config_overview>` and :ref:`here
526 530 <configuring_ipython>`.
527 531
528 532 * The old IPython extension API that relied on :func:`ipapi` has been
529 533 completely removed. The new extension API is described :ref:`here
530 534 <configuring_ipython>`.
531 535
532 536 * Support for ``qt3`` has been dropped. Users who need this should use
533 537 previous versions of IPython.
534 538
535 539 * Removed :mod:`shellglobals` as it was obsolete.
536 540
537 541 * Removed all the threaded shells in :mod:`IPython.core.shell`. These are no
538 542 longer needed because of the new capabilities in
539 543 :mod:`IPython.lib.inputhook`.
540 544
541 545 * New top-level sub-packages have been created: :mod:`IPython.core`,
542 546 :mod:`IPython.lib`, :mod:`IPython.utils`, :mod:`IPython.deathrow`,
543 547 :mod:`IPython.quarantine`. All existing top-level modules have been
544 548 moved to appropriate sub-packages. All internal import statements
545 549 have been updated and tests have been added. The build system (setup.py
546 550 and friends) have been updated. See :ref:`this section <module_reorg>` of the
547 551 documentation for descriptions of these new sub-packages.
548 552
549 553 * :mod:`IPython.ipapi` has been moved to :mod:`IPython.core.ipapi`.
550 554 :mod:`IPython.Shell` and :mod:`IPython.iplib` have been split and removed as
551 555 part of the refactor.
552 556
553 557 * :mod:`Extensions` has been moved to :mod:`extensions` and all existing
554 558 extensions have been moved to either :mod:`IPython.quarantine` or
555 559 :mod:`IPython.deathrow`. :mod:`IPython.quarantine` contains modules that we
556 560 plan on keeping but that need to be updated. :mod:`IPython.deathrow` contains
557 561 modules that are either dead or that should be maintained as third party
558 562 libraries. More details about this can be found :ref:`here <module_reorg>`.
559 563
560 564 * Previous IPython GUIs in :mod:`IPython.frontend` and :mod:`IPython.gui` are
561 565 likely broken, and have been removed to :mod:`IPython.deathrow` because of the
562 566 refactoring in the core. With proper updates, these should still work.
563 567
564 568
565 569 Known Regressions
566 570 -----------------
567 571
568 572 We do our best to improve IPython, but there are some known regressions in 0.11
569 573 relative to 0.10.2. First of all, there are features that have yet to be
570 574 ported to the new APIs, and in order to ensure that all of the installed code
571 575 runs for our users, we have moved them to two separate directories in the
572 576 source distribution, `quarantine` and `deathrow`. Finally, we have some other
573 577 miscellaneous regressions that we hope to fix as soon as possible. We now
574 578 describe all of these in more detail.
575 579
576 580 Quarantine
577 581 ~~~~~~~~~~
578 582
579 583 These are tools and extensions that we consider relatively easy to update to
580 584 the new classes and APIs, but that we simply haven't had time for. Any user
581 585 who is interested in one of these is encouraged to help us by porting it and
582 586 submitting a pull request on our `development site`_.
583 587
584 588 .. _development site:: http://github.com/ipython/ipython
585 589
586 590 Currently, the quarantine directory contains::
587 591
588 592 clearcmd.py ipy_fsops.py ipy_signals.py
589 593 envpersist.py ipy_gnuglobal.py ipy_synchronize_with.py
590 594 ext_rescapture.py ipy_greedycompleter.py ipy_system_conf.py
591 595 InterpreterExec.py ipy_jot.py ipy_which.py
592 596 ipy_app_completers.py ipy_lookfor.py ipy_winpdb.py
593 597 ipy_autoreload.py ipy_profile_doctest.py ipy_workdir.py
594 598 ipy_completers.py ipy_pydb.py jobctrl.py
595 599 ipy_editors.py ipy_rehashdir.py ledit.py
596 600 ipy_exportdb.py ipy_render.py pspersistence.py
597 601 ipy_extutil.py ipy_server.py win32clip.py
598 602
599 603 Deathrow
600 604 ~~~~~~~~
601 605
602 606 These packages may be harder to update or make most sense as third-party
603 607 libraries. Some of them are completely obsolete and have been already replaced
604 608 by better functionality (we simply haven't had the time to carefully weed them
605 609 out so they are kept here for now). Others simply require fixes to code that
606 610 the current core team may not be familiar with. If a tool you were used to is
607 611 included here, we encourage you to contact the dev list and we can discuss
608 612 whether it makes sense to keep it in IPython (if it can be maintained).
609 613
610 614 Currently, the deathrow directory contains::
611 615
612 616 astyle.py ipy_defaults.py ipy_vimserver.py
613 617 dtutils.py ipy_kitcfg.py numeric_formats.py
614 618 Gnuplot2.py ipy_legacy.py numutils.py
615 619 GnuplotInteractive.py ipy_p4.py outputtrap.py
616 620 GnuplotRuntime.py ipy_profile_none.py PhysicalQInput.py
617 621 ibrowse.py ipy_profile_numpy.py PhysicalQInteractive.py
618 622 igrid.py ipy_profile_scipy.py quitter.py*
619 623 ipipe.py ipy_profile_sh.py scitedirector.py
620 624 iplib.py ipy_profile_zope.py Shell.py
621 625 ipy_constants.py ipy_traits_completer.py twshell.py
622 626
623 627
624 628 Other regressions
625 629 ~~~~~~~~~~~~~~~~~
626 630
627 631 * The machinery that adds functionality to the 'sh' profile for using IPython
628 632 as your system shell has not been updated to use the new APIs. As a result,
629 633 only the aesthetic (prompt) changes are still implemented. We intend to fix
630 634 this by 0.12. Tracked as issue 547_.
631 635
632 636 .. _547: https://github.com/ipython/ipython/issues/547
633 637
634 638 * The installation of scripts on Windows was broken without setuptools, so we
635 639 now depend on setuptools on Windows. We hope to fix setuptools-less
636 640 installation, and then remove the setuptools dependency. Issue 539_.
637 641
638 642 .. _539: https://github.com/ipython/ipython/issues/539
639 643
640 644 * The directory history `_dh` is not saved between sessions. Issue 634_.
641 645
642 646 .. _634: https://github.com/ipython/ipython/issues/634
643 647
644 648
645 649 Removed Features
646 650 ----------------
647 651
648 652 As part of the updating of IPython, we have removed a few features for the
649 653 purpsoes of cleaning up the codebase and interfaces. These removals are
650 654 permanent, but for any item listed below, equivalent functionality is
651 655 available.
652 656
653 657 * The magics Exit and Quit have been dropped as ways to exit IPython. Instead,
654 658 the lowercase forms of both work either as a bare name (``exit``) or a
655 659 function call (``exit()``). You can assign these to other names using
656 660 exec_lines in the config file.
657 661
658 662
659 663 .. _credits_011::
660 664
661 665 Credits
662 666 -------
663 667
664 668 Many users and developers contributed code, features, bug reports and ideas to
665 669 this release. Please do not hesitate in contacting us if we've failed to
666 670 acknowledge your contribution here. In particular, for this release we have
667 671 contribution from the following people, a mix of new and regular names (in
668 672 alphabetical order by first name):
669 673
670 674 * Aenugu Sai Kiran Reddy <saikrn08-at-gmail.com>
671 675 * andy wilson <wilson.andrew.j+github-at-gmail.com>
672 676 * Antonio Cuni <antocuni>
673 677 * Barry Wark <barrywark-at-gmail.com>
674 678 * Beetoju Anuradha <anu.beethoju-at-gmail.com>
675 679 * Benjamin Ragan-Kelley <minrk-at-Mercury.local>
676 680 * Brad Reisfeld
677 681 * Brian E. Granger <ellisonbg-at-gmail.com>
678 682 * Christoph Gohlke <cgohlke-at-uci.edu>
679 683 * Cody Precord
680 684 * dan.milstein
681 685 * Darren Dale <dsdale24-at-gmail.com>
682 686 * Dav Clark <davclark-at-berkeley.edu>
683 687 * David Warde-Farley <wardefar-at-iro.umontreal.ca>
684 688 * epatters <ejpatters-at-gmail.com>
685 689 * epatters <epatters-at-caltech.edu>
686 690 * epatters <epatters-at-enthought.com>
687 691 * Eric Firing <efiring-at-hawaii.edu>
688 692 * Erik Tollerud <erik.tollerud-at-gmail.com>
689 693 * Evan Patterson <epatters-at-enthought.com>
690 694 * Fernando Perez <Fernando.Perez-at-berkeley.edu>
691 695 * Gael Varoquaux <gael.varoquaux-at-normalesup.org>
692 696 * Gerardo <muzgash-at-Muzpelheim>
693 697 * Jason Grout <jason.grout-at-drake.edu>
694 698 * John Hunter <jdh2358-at-gmail.com>
695 699 * Jens Hedegaard Nielsen <jenshnielsen-at-gmail.com>
696 700 * Johann Cohen-Tanugi <johann.cohentanugi-at-gmail.com>
697 701 * Jörgen Stenarson <jorgen.stenarson-at-bostream.nu>
698 702 * Justin Riley <justin.t.riley-at-gmail.com>
699 703 * Kiorky
700 704 * Laurent Dufrechou <laurent.dufrechou-at-gmail.com>
701 705 * Luis Pedro Coelho <lpc-at-cmu.edu>
702 706 * Mani chandra <mchandra-at-iitk.ac.in>
703 707 * Mark E. Smith
704 708 * Mark Voorhies <mark.voorhies-at-ucsf.edu>
705 709 * Martin Spacek <git-at-mspacek.mm.st>
706 710 * Michael Droettboom <mdroe-at-stsci.edu>
707 711 * MinRK <benjaminrk-at-gmail.com>
708 712 * muzuiget <muzuiget-at-gmail.com>
709 713 * Nick Tarleton <nick-at-quixey.com>
710 714 * Nicolas Rougier <Nicolas.rougier-at-inria.fr>
711 715 * Omar Andres Zapata Mesa <andresete.chaos-at-gmail.com>
712 716 * Paul Ivanov <pivanov314-at-gmail.com>
713 717 * Pauli Virtanen <pauli.virtanen-at-iki.fi>
714 718 * Prabhu Ramachandran
715 719 * Ramana <sramana9-at-gmail.com>
716 720 * Robert Kern <robert.kern-at-gmail.com>
717 721 * Sathesh Chandra <satheshchandra88-at-gmail.com>
718 722 * Satrajit Ghosh <satra-at-mit.edu>
719 723 * Sebastian Busch
720 724 * Skipper Seabold <jsseabold-at-gmail.com>
721 725 * Stefan van der Walt <bzr-at-mentat.za.net>
722 726 * Stephan Peijnik <debian-at-sp.or.at>
723 727 * Steven Bethard
724 728 * Thomas Kluyver <takowl-at-gmail.com>
725 729 * Thomas Spura <tomspur-at-fedoraproject.org>
726 730 * Tom Fetherston <tfetherston-at-aol.com>
727 731 * Tom MacWright
728 732 * tzanko
729 733 * vankayala sowjanya <hai.sowjanya-at-gmail.com>
730 734 * Vivian De Smedt <vds2212-at-VIVIAN>
731 735 * Ville M. Vainio <vivainio-at-gmail.com>
732 736 * Vishal Vatsa <vishal.vatsa-at-gmail.com>
733 737 * Vishnu S G <sgvishnu777-at-gmail.com>
734 738 * Walter Doerwald <walter-at-livinglogic.de>
735 739
736 740 .. note::
737 741
738 742 This list was generated with the output of
739 743 ``git log dev-0.11 HEAD --format='* %aN <%aE>' | sed 's/@/\-at\-/' | sed 's/<>//' | sort -u``
740 744 after some cleanup. If you should be on this list, please add yourself.
741 745
742 746
743 747 .. _issues_list_011:
744 748
745 749 Closed issues
746 750 =============
747 751
748 752 .. include:: github-stats-011.txt
General Comments 0
You need to be logged in to leave comments. Login now