iPython - 在配置文件中设置魔术命令 [英] iPython - set up magic commands in configuration file

查看:258
本文介绍了iPython - 在配置文件中设置魔术命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我主要通过笔记本电脑使用iPython,也使用终端。我刚刚通过运行 ipython profile create 创建了我的默认配置文件。

I use iPython mostly via notebooks but also in the terminal. I just created my default profile by running ipython profile create.

我似乎无法弄清楚如何让配置文件运行我每次使用的几个魔术命令。我试着在网上和我正在阅读的一本书中查看这个但是无法让它工作。例如,如果我想为每个新笔记本激活%debug ,我尝试将这些行添加到我的配置文件中:

I can't seem to figure out how to have the profile run several magic commands that I use every time. I tried to look this up online and in a book I'm reading but can't get it to work. For example, if I want %debug activated for every new notebook I tried adding these lines to my config file:

c.InteractiveShellApp.extensions = ['debug']

c.TerminalPythonApp.extensions = ['debug']

我得到导入错误或什么都没有。我的(密切相关的)问题如下:

and I either get import errors or nothing. My (closely related) questions are the following:


  1. 我要添加到ipython配置文件以激活魔术命令的行?一些需要参数,例如%reload_ext autoreload %autoreload 2 。我如何在配置文件中传递这些参数?

  1. What line to do I add to my ipython config file to activate magic commands? Some require parameters, e.g. %reload_ext autoreload and %autoreload 2. How do I also pass these parameters in the config file?

我可以在单个配置文件中分离为终端与笔记本添加哪些参数,还是必须设置如果我想要激活不同的魔法,可以单独创建配置文件? (例如, matplotlib 内联与否)。以上两行是否会影响笔记本电脑与终端设置(即 c.InteractiveShellApp c.TerminalPythonApp )?

Can I separate which get added for terminal vs. notebooks in a single config file or must I set up separate profiles if I want different magic's activated? (e.g., matplotlib inline or not). Do the two lines above affect notebooks vs. terminal settings (i.e., c.InteractiveShellApp vs. c.TerminalPythonApp)?

谢谢!

推荐答案

按如下方式执行魔法:

get_ipython().magic(u"%reload_ext autoreload")
get_ipython().magic(u"%autoreload 2")

你可以将这些行放入你的这里的启动脚本:

You can put those lines in your startup script here:

~/.ipython/profile_default/startup/00-first.py

这篇关于iPython - 在配置文件中设置魔术命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆