Searching for Signal

the n01se blog

Load virtualenvwrapper on demand to speed up your shell

Loading virtualenvwrapper.sh takes too long:

 $ time source /usr/bin/virtualenvwrapper.sh
 real       0m1.034s
 user       0m0.625s
 sys        0m0.161s

If you load virtualenvwrapper.sh in your .bashrc, this means waiting an extra second every time you open a terminal. But you can avoid the delay by loading the functions on demand! The trick is to create stub functions workon, deactivate and mkvirtualenv that will load virtualenvwrapper.sh and then run the real function.

To make this work, save the following snippet as .bashrc.virtualenvwrapper in your home directory:

Then replace source virtualenvwrapper.sh in your .bashrc with:

source ~/.bashrc.virtualenvwrapper

This loads in about 1/100 of a second, and the real virtualenvwrapper.sh will load when you first invoke workon or mkvirtualenv.