如何使用脚本重新创建IPython的'--pylab'选项的效果? [英] How can I recreate the effect of IPython's '--pylab' option with a script?
问题描述
我想创建一个与IPython的 - pylab
标记手动相同的配置文件。脚本的内容应该是什么 - 包导入,命名空间指定,设置等 - 来实现这个目标?
I'd like to create a profile that does the same thing as IPython's --pylab
flag "by hand". What should the contents of a script be — package imports, namespace designations, settings, etc. — to achieve this?
作为替代方案,我也有兴趣是否有办法检查当前IPython会话启动时是否设置了 - pylab
标志。
As an alternative, I'd also be interested in whether there is a way to check that the --pylab
flag was set when the current IPython session was launched.
只需从matplotlib.pylab导入导入*
不起作用,%pylab
(因为在配置文件中似乎不允许使用魔法)。
Simply doing from matplotlib.pylab import *
doesn't work, nor does %pylab
(since magics don't seem to be allowed in profiles).
推荐答案
深入了解帮助和男人页面( $ ipython --help-all
然后搜索pylab)显示:
Digging into the help and man pages ($ ipython --help-all
then followed by a search for "pylab") reveals:
--pylab=<CaselessStrEnum> (InteractiveShellApp.pylab) # mean is an alias for
--InteractiveShellApp.pylab=<CaselessStrEnum>
Default: None
Choices: ['auto', 'gtk', 'inline', 'osx', 'qt', 'qt4', 'tk', 'wx']
Pre-load matplotlib and numpy for interactive use, selecting a particular
matplotlib backend and loop integration.
--InteractiveShellApp.pylab_import_all=<Bool>
Default: True
If true, IPython will populate the user namespace with numpy, pylab, etc.
and an ``import *`` is done from numpy and pylab, when using pylab mode.
When False, pylab mode should not import any names into the user namespace.
所以 c.InteractiveShellApp.pylab = 'auto'
无论配置或个人资料诀窍。
(同意Andrew这样隐藏的是unpythonic。)
(Agreed with Andrew that hiding like this is unpythonic.)
这篇关于如何使用脚本重新创建IPython的'--pylab'选项的效果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!