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?
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.
Simply doing from matplotlib.pylab import *
doesn't work, nor does %pylab
(since magics don't seem to be allowed in profiles).
Digging into the help and man pages (
$ ipython --help-all
then followed by a search for "pylab") reveals:So
c.InteractiveShellApp.pylab='auto'
in whatever configuration or profile you are loading will do the trick.(Agreed with Andrew that hiding like this is unpythonic.)
In an ipython sense, you can do this by creating a new iPython profile
Edit the ipython_config.py directory. On newer installs of ipython under linux, this file will be in
~/.config/ipython/profile_<name>
directory, but you can find it if you're unsure with:For me, I can I edit the appropriate file with the bash command:
Edit the appropriate variables in that file (see the ipython docs).
In a more general sense, you can force python to run arbitrary code at startup by setting the
PYTHONSTARTUP
environment variable, and pointing it at a python file with commands in it. To be equivalent to--pylab
that file would need to have the following contents (equivalent to ipython 1.1).From past experience setting your
PYTHONSTARTUP
variable is probably a bad idea. All your Python code must have an x-session (or equivalent), unless you're setting a backend that doesn't pop up a plot window. It also pollutes the global namespace for everything you run and will slow down the interpreter (matplotlib in particular takes a noticeable amount of time to import on my machines).