Automatically import module when starting Jupyter applications (QtConsole)

384 views
Skip to first unread message

FSund

unread,
Jul 4, 2016, 7:25:21 AM7/4/16
to Project Jupyter
I want to have numpy loaded as np and matplotlib.pyplot loaded as plt when I start Jupyter QtConsole session. 

Earlier I could do this by adding

c.InteractiveShellApp.exec_lines = [
    'import numpy as np',
    'import matplotlib.pyplot',
]

to .ipython/ipython_config.py, but newer version of Jupyter has moved away from using that config file. 

I've tried adding it to jupyter_qtconsole_config.py, but that doesn't work.

What is the best way of doing this today?

Thomas Kluyver

unread,
Jul 4, 2016, 7:37:24 AM7/4/16
to Project Jupyter
On 4 July 2016 at 12:25, FSund <filip...@gmail.com> wrote:
to .ipython/ipython_config.py, but newer version of Jupyter has moved away from using that config file. 

Importing modules on startup is the responsibility of the IPython kernel (as it's Python specific), so it's still configured through IPython, not in any Jupyter config file. The location is .ipython/profile_default/ipython_config.py (unchanged from before), but configuring it there should still work.

More information on configuring IPython:
http://ipython.readthedocs.io/en/stable/config/index.html

FSund

unread,
Jul 4, 2016, 7:46:36 AM7/4/16
to Project Jupyter
Aha, now I see. Thank you very much.
I was under the impression that IPython was no more, and that it had all been replaced by Jupyter.

The whole IPython/Jupyter stuff can be pretty confusing for a beginner, but I still find QtConsole immensely useful.

Thomas Kluyver

unread,
Jul 4, 2016, 8:06:38 AM7/4/16
to Project Jupyter
On 4 July 2016 at 12:46, FSund <filip...@gmail.com> wrote:
The whole IPython/Jupyter stuff can be pretty confusing for a beginner, but I still find QtConsole immensely useful.

It certainly can. The rule of thumb is: Jupyter is all the pieces that can work with other languages, IPython is the Python-specific backend for Jupyter.
Reply all
Reply to author
Forward
0 new messages