[Distutils] "activate" script for virtualenv

Matt Good matt at matt-good.net
Fri Sep 28 23:07:59 CEST 2007


I just set up a little script so that I can activate a particular  
virtualenv and easily exit it.  Basically it just invokes a new bash  
subshell and sets the PATH to include the current bin dir:

mgood at sjl-dev1:~/python-envs/trac$ cat activate
bash --init-file .bash_init
mgood at sjl-dev1:~/python-envs/trac$ cat .bash_init
. ~/.bash_profile
export PATH="`pwd`/bin:$PATH"

So running ./activate will set up your path in the subshell, and  
exiting will restore your normal PATH.  I don't really like running  
~/.bash_profile again b/c I actually end up with it re-adding some  
stuff that's already in the PATH, but otherwise I lost my normal  
prompt coloring.  Someone with more bash-fu know how to fix that?

mgood at sjl-dev1:~/python-envs/trac$ which python
/usr/local/bin/python
mgood at sjl-dev1:~/python-envs/trac$ ./activate
mgood at sjl-dev1:~/python-envs/trac$ which python
/home/mgood/python-envs/trac/bin/python
mgood at sjl-dev1:~/python-envs/trac$ exit
mgood at sjl-dev1:~/python-envs/trac$ which python
/usr/local/bin/python

-- Matt


More information about the Distutils-SIG mailing list