在切换到 IPython v0.11(使用 Python 2.6.1)之前,可以使用例如 这个,例如
from IPython.Shell import IPShellEmbed
ipshell = IPShellEmbed()
ipshell() # this call anywhere in your program will start IPython
“嵌入式 shell 已被重构为一个真正独立的 InteractiveShell 子类,称为 InteractiveShellEmbed em>。所有嵌入逻辑已从基类中取出并放入嵌入子类中”(请参阅此处和此处 )。
按照我的理解,您现在应该能够简单地启动控制台
import IPython
IPython.embed()
但是,这会引发
TraitError:InteractiveShellEmbed 实例的“exit_msg”特征必须是字符串,但指定了值 u''。
如果我们为 exit_msg
传递一个字符串,那么
IPython.embed(exit_msg='Whatever')
它会引发不同的错误
AttributeError:“InteractiveShellEmbed”对象没有属性“set_completer”
其他人遇到过这个问题吗?否则这可能是一个错误,因为它毕竟是开发人员版本。
Before switching to IPython v0.11 (using Python 2.6.1), it was possible to embed an interactive IPython shell using for example this, e.g.
from IPython.Shell import IPShellEmbed
ipshell = IPShellEmbed()
ipshell() # this call anywhere in your program will start IPython
"The embedded shell has been refactored into a truly standalone subclass of InteractiveShell called InteractiveShellEmbed. All embedding logic has been taken out of the base class and put into the embedded subclass" (see here and here).
The way I understand it you should now be able to simply start a console by
import IPython
IPython.embed()
However, this raises
TraitError: The 'exit_msg' trait of an InteractiveShellEmbed instance must be a string, but a value of u'' was specified.
If we pass a string for exit_msg
by
IPython.embed(exit_msg='Whatever')
Then it raises a different error
AttributeError: 'InteractiveShellEmbed' object has no attribute 'set_completer'
Did anybody else encounter this problem? Otherwise this might be a bug since it is a developer version after all.
发布评论
评论(2)
如今(3.0+)您需要做的就是:
如果您的意思是在 IPython 中嵌入另一个 IPython shell(递归地),那么很长一段时间以来都不支持这一点,但这个问题在去年得到了修补。
These days (3.0+) all you need to do is:
If you mean embedding another IPython shell in IPython (recursively), there was a long time that this was not supported, but that problem was patched last year.
有 具体github wiki 上的说明:
There are specific instructions on the github wiki: