IPython - setting magic commands in a configuration file

I use iPython mainly through laptops, but also in the terminal. I just created my default profile by running ipython profile create.

I can’t figure out how to make the profile run several magic commands that I use every time. I tried to watch it online and in the book that I am reading, but cannot make it work. For example, if I want to be %debugactivated for each new laptop, I tried to add these lines to my configuration file:

c.InteractiveShellApp.extensions = ['debug']

or

c.TerminalPythonApp.extensions = ['debug']

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

  • What line can I add to my ipython configuration file to activate magic commands? Some of them require parameters, for example. %reload_ext autoreloadand %autoreload 2. How to transfer these parameters in the configuration file?

  • Can I separate which is added for terminals or laptops in one configuration file, or do I need to configure separate profiles if I want another magic to be activated? (e.g. matplotlibembedded or not). Do the above two lines affect the settings of laptops and terminals (i.e. c.InteractiveShellAppagainst c.TerminalPythonApp)?

Thanks!

+4
source share
2 answers

Perform the magic as follows:

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

You can put these lines in your script run here:

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

, , magic pylab :

ipython profile create pylab

.ipython\profile_pylab\ipython_config.py

c.InteractiveShellApp.exec_lines = ['%pylab']

ipython

ipython --profile=pylab
0

Source: https://habr.com/ru/post/1608220/


All Articles