iPython is a great replacement for the standard Python shell, but, out of the box, it doesn’t play well with virtualenv.
This can be fixed with a couple of changes:
In the terminal generate an iPython default config file:
ipython profile create
Open the newly generated file:
vi ~/.ipython/profile_default/ipython_config.py
Add the following code at the end of the ipython_config.py file:
import site
from os import environ
from os.path import join
from sys import version_info
if 'VIRTUAL_ENV' in environ:
virtual_env = join(environ.get('VIRTUAL_ENV'),
'lib',
'python%d.%d' % version_info[:2],
'site-packages')
site.addsitedir(virtual_env)
print 'VIRTUAL_ENV ->', virtual_env
del virtual_env
del site, environ, join, version_info
And that’s it, iPython should now be virtualenv aware.