Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

Automagically import missing modules in IPython.

Project Description

Automagically import missing modules in IPython: instead of

In [1]: plt.plot([1, 2], [3, 4])
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-1-994ba2bf13c0> in <module>()
----> 1 plt.plot([1, 2], [3, 4])

NameError: name 'plt' is not defined

In [2]: from matplotlib import pyplot as plt

In [3]: plt.plot([1, 2], [3, 4])
Out[3]: [<matplotlib.lines.Line2D at 0x7f73f0179198>]

do what I mean:

In [1]: plt.plot([1, 2], [3, 4])
Autoimport: from matplotlib import pyplot as plt
Out[1]: [<matplotlib.lines.Line2D at 0x7f7e253552b0>]

Inspired from @OrangeFlash81’s version, with many improvements:

  • Does not rely on re-execution, but instead hooks the user namespace; thus, safe even in the presence of side effects, and works for tab completion and magics too.
  • Learns your preferred aliases (from the history).
  • Suppresses irrelevant chained tracebacks.
  • Auto-imports submodules.
  • pip-installable.

Installation

Pick one among:

$ pip install ipython-autoimport  # from PyPI
$ pip install git+https://github.com/anntzer/ipython-autoimport  # from Github

then append the output of python -mipython_autoimport to the output of ipython profile locate (typically ~/.ipython/profile_default/ipython_config.py).

Run tests with pytest (tests requires pathlib on Python 3.3).

Limitations

  • Comprehension scopes (e.g. [x for x in <autoimported-module-attribute>]) do not support autoimporting. The reason for this limitation is described in detail as a comment to load_ipython_extension. A fix would be welcome.
Release History

Release History

This version
History Node

0.2

History Node

0.1

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
ipython_autoimport-0.2-py3-none-any.whl (6.5 kB) Copy SHA256 Checksum SHA256 py3 Wheel May 6, 2017

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting