我主要通过笔记本使用 iPython,但也在终端中使用。我刚刚通过运行创建了我的默认配置文件ipython profile create
.
我似乎无法弄清楚如何让配置文件运行我每次使用的几个神奇命令。我试图在网上和我正在读的书中查找这一点,但无法使其发挥作用。例如,如果我想要%debug
为每个新笔记本激活我尝试将这些行添加到我的配置文件中:
c.InteractiveShellApp.extensions = ['debug']
or
c.TerminalPythonApp.extensions = ['debug']
我要么收到导入错误,要么什么也没有。我的(密切相关的)问题如下:
我需要在 ipython 配置文件中添加哪一行来激活 magic 命令?有些需要参数,例如%reload_ext autoreload
and %autoreload 2
。我如何在配置文件中传递这些参数?
我可以在单个配置文件中将终端与笔记本添加的内容分开吗?或者如果我想激活不同的魔法,我必须设置单独的配置文件吗? (例如。,matplotlib
内联与否)。上面两行是否会影响笔记本电脑与终端设置(即c.InteractiveShellApp
vs. c.TerminalPythonApp
)?
谢谢你!
执行魔法如下:
get_ipython().magic(u"%reload_ext autoreload")
get_ipython().magic(u"%autoreload 2")
您可以将这些行放入您的启动脚本中:
~/.ipython/profile_default/startup/00-first.py
Update:从 IPython v0.13 开始,run_line_magic https://ipython.readthedocs.io/en/stable/api/generated/IPython.core.interactiveshell.html#IPython.core.interactiveshell.InteractiveShell.run_line_magic应该使用函数而不是magic https://ipython.readthedocs.io/en/stable/api/generated/IPython.core.interactiveshell.html#IPython.core.interactiveshell.InteractiveShell.magic功能:
get_ipython().run_line_magic("reload_ext", "autoreload")
get_ipython().run_line_magic("autoreload", "2")
否则您会收到弃用警告。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)