Setup ipython to work in a virtualenv

Monday, August 29, 2011

add this script to \~/.ipython/ipython_virtualenv.py

#Call this inside ~/.ipython/ipy_user_conf.py main()

import sys
import subprocess
from os import environ

if 'VIRTUAL_ENV' in environ:
    #This is kludgy but it works; grab the right sys.path from the virtualenv python install:
    path = subprocess.Popen(['python', '-c','import sys;print(repr(sys.path))'],
                            stdout=subprocess.PIPE).communicate()[0]
    sys.path = eval(path)
    del path

del sys, subprocess, environ

from https://gist.github.com/817737

This entry was tagged Python

comments powered by Disqus

© 2009-2013 lxneng.com. All rights reserved. Powered by Pyramid

go to Top