Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IPython: load extension automatically upon start

Tags:

ipython

In IPython, I can load a custom extension using simple command:

%load_ext physics

This will load the file ~/.ipython/extensions/physics.py.

How can I tell IPython to load the extension automatically on startup?

I have added the line to /.ipython/profile_default/startup/import.py, but that does not work:

from numpy import *

%load_ext physics

When I start IPython, I get folowing error:

File "~/.ipython/profile_default/startup/import.py", line 17
%load_ext physics
^
SyntaxError: invalid syntax
like image 472
Martin Vegter Avatar asked Aug 07 '15 08:08

Martin Vegter


People also ask

What does Autoreload 2 do?

autoreload reloads modules automatically before entering the execution of code typed at the IPython prompt. The module was reloaded without reloading it explicitly, and the object imported with from foo import ... was also updated.

What is Autoreload?

Autoreload is a simple python script to watch a directory for changed files and restarts a process when the change is detected. autoreload. #!/usr/bin/env python.

What is IPython extension?

An IPython extension is an importable Python module that has a couple of special functions to load and unload it. Here is a template: # myextension.py def load_ipython_extension(ipython): # The `ipython` argument is the currently active `InteractiveShell` # instance, which can be used in any way.

What is IPython shell?

IPython (Interactive Python) is a command shell for interactive computing in multiple programming languages, originally developed for the Python programming language, that offers introspection, rich media, shell syntax, tab completion, and history.


1 Answers

From the IPython documentation:

Using extensions

To load an extension while IPython is running, use the %load_ext magic:

In [1]: %load_ext myextension

To load it each time IPython starts, list it in your configuration file:

c.InteractiveShellApp.extensions = [
    'myextension'
]

Hope that helps

like image 117
Joseph Stover Avatar answered Oct 30 '22 20:10

Joseph Stover