ipython/ipython — Issue #1171: Recognise virtualenvs
Author: takluyver
Created: 2011-12-17 23:33:01+00:00
State: open

A recurring issue, which I've just added to the FAQ - a standard installation of IPython won't recognise when you're in a virtualenv. Various workarounds are showing up, but it would be good to work out of the box.

The root of the problem is that the installation sets the shebang line of ipython to `#!/usr/bin/python`. If it's `#!/usr/bin/env python`, virtualenvs work as expected. (I don't know what the status is on Windows)

A few possible ways to deal with this:

* Get an option added to distutils/packaging/setuptools/distribute to control the shebang line written. Long term at best.
* For Linux distributions, the shebang could be replaced as a step in the packaging.
* Contribute ipython-awareness to virtualenv, so if IPython is installed, it will copy the script and update the shebang line when you create a virtualenv.
* Detect when we're in a virtualenv, and add the relevant paths to sys.path. This is suboptimal, because it only affects importable libraries, not the interpreter itself (e.g. if I make a Python 2.6 virtualenv, IPython will still start with the default Python 2.7).