Auto-load a module on python startup

rubik picture rubik · Oct 23, 2010 · Viewed 11.7k times · Source

I want IPython or the Python interpreter to auto-load a module when I start them.

Is it possible?

For example when I start IPython:

$ ipython

...

>>> from __future__ import division
>>> from mymodule import *

In [1]:

Something like SymPy's live shell found in the tutorial pages.

Answer

pyfunc picture pyfunc · Oct 23, 2010

Have a .pythonstartup in your home directory and load modules there and point PYTHONSTARTUP env to that file.

Python commands in that file are executed before the first prompt is displayed in interactive mode.

I use it for enabling command line completion in python interpreter shell