Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/aaronc81/ipython-auto-import

:inbox_tray: Automatically import a Python library in IPython when you forget to import it
https://github.com/aaronc81/ipython-auto-import

ipython python python3

Last synced: 3 months ago
JSON representation

:inbox_tray: Automatically import a Python library in IPython when you forget to import it

Awesome Lists containing this project

README

        

# ipython-auto-import

How many times have you quickly wanted to test something, only to do this?

```
In [1]: df = pandas.read_clipboard()
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
in ()
----> 1 df = pandas.read_clipboard()

NameError: name 'pandas' is not defined

In [2]: import pandas # *sigh*

In [3]: df = pandas.read_clipboard()
```

Inspired by [this SO question](http://stackoverflow.com/questions/36112275/make-ipython-import-what-i-mean/36116171#36116171), you'll never need to import a module again in IPython!

```
In [1]: pandas.read_clipboard()
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
in ()
----> 1 pandas.read_clipboard()

NameError: name 'pandas' is not defined
AutoImport: Imported referenced module "pandas", will retry
---------------------------------------------------------------------------
Out[1]:
First,Last
0 Foo,Bar
1 John,Appleseed
```

The first time you reference a module, it imports it auto-magically! Don't have the module installed? You can `pip install` it right from IPython.

## Installation

**NOTE**: It's recommended that you install `colorama` for best results: `pip install colorama`

### Easy way
Clone the repo and run `install.py`.

### Hard way
Add `import_wrapper.py` to `~/.ipython/extensions`, then call `%load_ext import_wrapper` either at the IPython prompt, or add
```
c.InteractiveShellApp.exec_lines.append("%load_ext import_wrapper")
```
at the end of `~/.ipython/profile_default/ipython_config.py`.