virtualenvwrapper.sh adds 200-500ms to my shell initialization time

48 views
Skip to first unread message

David Foster

unread,
Jun 13, 2013, 12:39:39 AM6/13/13
to virtuale...@googlegroups.com
This slows me down. Consider deferring expensive operations in virtualenvwrapper.sh to minimize the setup time.

# Repro Steps

time bash -l -i -c 'exit'

If you run the above line when commenting out vs. leaving in the 'source [...]/virtualenvwrapper.sh' inside .bashrc, the timing can increase as much as 900ms (but typically something closer to 200ms).

# Workaround

Defer import of virtualenvwrapper until it is used. This avoids the setup time overhead on the many shells that don't use virtualenvwrapper. Here is an example of what you could add to .bashrc to accomplish this:

# virtualenvwrapper
venv_init () {
    export VIRTUALENVWRAPPER_PYTHON=`which python`
    export WORKON_HOME=/Users/davidf/Projects/.virtualenvs
    source /Library/Frameworks/Python.framework/Versions/2.7/bin/virtualenvwrapper.sh
}
# (Lazily import virtualenvwrapper for common commands, since it takes 200ms+ to import)
mkvirtualenv ()     { venv_init; mkvirtualenv $@; }
lsvirtualenv ()     { venv_init; lsvirtualenv $@; }
showvirtualenv ()   { venv_init; showvirtualenv $@; }
rmvirtualenv ()     { venv_init; rmvirtualenv $@; }
workon ()           { venv_init; workon $@; }
deactivate ()       { venv_init; deactivate $@; }

Doug Hellmann

unread,
Jun 13, 2013, 6:52:48 AM6/13/13
to virtuale...@googlegroups.com, virtuale...@googlegroups.com
You can achieve the same thing with the lazy loader. See http://virtualenvwrapper.readthedocs.org/en/latest/install.html#shell-startup-file

Doug
--
You received this message because you are subscribed to the Google Groups "virtualenvwrapper" group.
To unsubscribe from this group and stop receiving emails from it, send an email to virtualenvwrap...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply all
Reply to author
Forward
0 new messages