Automatically import a Python library in IPython when you forget to import it
MIT License
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)
<ipython-input-1-45ec783f831b> in <module>()
----> 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, you'll never need to import a module again in IPython!
In [1]: pandas.read_clipboard()
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-1-4c32fab697e6> in <module>()
----> 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.
NOTE: It's recommended that you install colorama
for best results: pip install colorama
Clone the repo and run install.py
.
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
.