2011-03-28 33 views
6

Antes de cambiar a IPython v0.11 (utilizando Python 2.6.1), era posible incrustar un shell interactivo de IPython usando, por ejemplo, this, p. Ej.Shell interactivo incorporado en IPython

from IPython.Shell import IPShellEmbed 
ipshell = IPShellEmbed() 
ipshell() # this call anywhere in your program will start IPython 

"La cáscara incrustado ha sido refactorizado en una subclase verdaderamente independiente de InteractiveShell llamado InteractiveShellEmbed. Toda la lógica incrustación se ha sacado de la clase base y poner en la subclase incrustado" (ver here y here).

La manera en que yo lo entiendo ahora debería ser capaz de simplemente iniciar una consola por

import IPython 
IPython.embed() 

Sin embargo, esto plantea

TraitError: The 'exit_msg' trait of an InteractiveShellEmbed instance must be a string, but a value of u'' was specified.

Si se pasa una cadena para exit_msg por

IPython.embed(exit_msg='Whatever') 

Luego se genera un error diferente

AttributeError: 'InteractiveShellEmbed' object has no attribute 'set_completer'

¿Alguien más ha tenido este problema? De lo contrario, esto podría ser un error, ya que es una versión de desarrollador después de todo.

Respuesta

3

Hay specific instructions en el wiki de GitHub:

from IPython.frontend.terminal.ipapp import TerminalIPythonApp 
app = TerminalIPythonApp.instance() 
app.initialize(argv=[]) # argv=[] instructs IPython to ignore sys.argv 
app.start() 
9

En estos días (3.0+) todo lo que necesita hacer es:

from IPython import embed; embed() 

Si se refiere a la incorporación de otro proyectil IPython en IPython (de forma recursiva), hubo un largo tiempo que esto no fue respaldado, pero ese problema fue reparado el año pasado.

Cuestiones relacionadas