Added more robust check for pip and virtualenv

Also fixes a bug noticed by k4rtik on irc, where VIRTUALENV actually wasn't previously defined.