def init_virtualenv(self):
    "Add the current virtualenv to sys.path so the user can import modules from it.\n        This isn't perfect: it doesn't use the Python interpreter with which the\n        virtualenv was built, and it ignores the --no-site-packages option. A\n        warning will appear suggesting the user installs IPython in the\n        virtualenv, but for many cases, it probably works well enough.\n\n        Adapted from code snippets online.\n\n        http://blog.ufsoft.org/2009/1/29/ipython-and-virtualenv\n        "
    if ('VIRTUAL_ENV' not in os.environ):
        return
    elif (os.environ['VIRTUAL_ENV'] == ''):
        warn("Virtual env path set to '', please check if this is intended.")
        return
    p = Path(sys.executable)
    p_venv = Path(os.environ['VIRTUAL_ENV'])
    paths = self.get_path_links(p)
    if (p_venv.parts[1] == 'cygdrive'):
        drive_name = p_venv.parts[2]
        p_venv = ((drive_name + ':/') / Path(*p_venv.parts[3:]))
    if any(((p_venv == p.parents[1]) for p in paths)):
        return
    if (sys.platform == 'win32'):
        virtual_env = str(Path(os.environ['VIRTUAL_ENV'], 'Lib', 'site-packages'))
    else:
        virtual_env_path = Path(os.environ['VIRTUAL_ENV'], 'lib', 'python{}.{}', 'site-packages')
        p_ver = sys.version_info[:2]
        re_m = re.search('\\bpy(?:thon)?([23])\\.(\\d+)\\b', os.environ['VIRTUAL_ENV'])
        if re_m:
            predicted_path = Path(str(virtual_env_path).format(*re_m.groups()))
            if predicted_path.exists():
                p_ver = re_m.groups()
        virtual_env = str(virtual_env_path).format(*p_ver)
    warn('Attempting to work in a virtualenv. If you encounter problems, please install IPython inside the virtualenv.')
    import site
    sys.path.insert(0, virtual_env)
    site.addsitedir(virtual_env)
Add the current virtualenv to sys.path so the user can import modules from it.
This isn't perfect: it doesn't use the Python interpreter with which the
virtualenv was built, and it ignores the --no-site-packages option. A
warning will appear suggesting the user installs IPython in the
virtualenv, but for many cases, it probably works well enough.

Adapted from code snippets online.

http://blog.ufsoft.org/2009/1/29/ipython-and-virtualenv
def init_virtualenv(self):
    "Add the current virtualenv to sys.path so the user can import modules from it.\n        This isn't perfect: it doesn't use the Python interpreter with which the\n        virtualenv was built, and it ignores the --no-site-packages option. A\n        warning will appear suggesting the user installs IPython in the\n        virtualenv, but for many cases, it probably works well enough.\n\n        Adapted from code snippets online.\n\n        http://blog.ufsoft.org/2009/1/29/ipython-and-virtualenv\n        "
    if ('VIRTUAL_ENV' not in os.environ):
        return
    elif (os.environ['VIRTUAL_ENV'] == ):
        warn("Virtual env path set to , please check if this is intended.")
        return
    p = Path(sys.executable)
    p_venv = Path(os.environ['VIRTUAL_ENV'])
    paths = self.get_path_links(p)
    if (p_venv.parts[1] == 'cygdrive'):
        drive_name = p_venv.parts[2]
        p_venv = ((drive_name + ':/') / Path(*p_venv.parts[3:]))
    if any(((p_venv == p.parents[1]) for p in paths)):
        return
    if (sys.platform == 'win32'):
        virtual_env = str(Path(os.environ['VIRTUAL_ENV'], 'Lib', 'site-packages'))
    else:
        virtual_env_path = Path(os.environ['VIRTUAL_ENV'], 'lib', 'python{}.{}', 'site-packages')
        p_ver = sys.version_info[:2]
        re_m = re.search('\\bpy(?:thon)?([23])\\.(\\d+)\\b', os.environ['VIRTUAL_ENV'])
        if re_m:
            predicted_path = Path(str(virtual_env_path).format(*re_m.groups()))
            if predicted_path.exists():
                p_ver = re_m.groups()
        virtual_env = str(virtual_env_path).format(*p_ver)
    warn('Attempting to work in a virtualenv. If you encounter problems, please install IPython inside the virtualenv.')
    import site
    sys.path.insert(0, virtual_env)
    site.addsitedir(virtual_env)