IPython and virtualenv
Recently I started developing my python applications using virtualenv so that I don't clutter up the system's python installation with non-system python packages.
Everything was good until I wanted to use IPython instead of python's shell...
The issue is that virtualenv creates a different python executable that includes the
virtualenv's packages into sys.path
while IPython stays unaware of the virtualenv's
packages.
Yet, there's a solution!!!
In order to solve this issue, IPython comes along to save the day.
IPython provides a way to include additional code to be executed when IPython's shell is started.
First, the small script that allows IPython to get virtualenv's packages into its sys.path
.
=
print ,
del
del , , ,
Save the above snippet into your user's IPython configuration directory ~/.ipython
.
Save it has, for example, virtualenv.py
.
Now, as IPython's documentation suggests, edit ~/.ipython/ipy_user_conf.py
and somewhere
inside the main()
function add:
Now, the next time you start IPython's shell, if you've activated your virtualenv environment, you’ll also get the packages from there too.
And that's it, there you have your virtualenv aware IPython shell!