Created
August 31, 2011 22:14
-
-
Save mvaz/1184879 to your computer and use it in GitHub Desktop.
script for ipython to work with virtualenv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import site | |
| from os import environ | |
| from os.path import join | |
| import sys | |
| if 'VIRTUAL_ENV' in environ: | |
| virtual_env = join(environ.get('VIRTUAL_ENV'), | |
| 'lib', | |
| 'python%d.%d' % sys.version_info[:2], | |
| 'site-packages') | |
| # Remember original sys.path. | |
| prev_sys_path = list(sys.path) | |
| site.addsitedir(virtual_env) | |
| # Reorder sys.path so new directories at the front. | |
| new_sys_path = [] | |
| for item in list(sys.path): | |
| if item not in prev_sys_path: | |
| new_sys_path.append(item) | |
| sys.path.remove(item) | |
| sys.path[1:1] = new_sys_path | |
| print 'VIRTUAL_ENV ->', virtual_env | |
| del virtual_env | |
| del site, environ, join, sys |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
setup to work with virtualenv
import os
c.InteractiveShellApp.exec_files = [
os.path.join( os.environ['HOME'], '.ipython', 'virtualenv.py' )
]