Make sure virtualenv activation also works on python 3.X.

execfile was removed in 3.X, use exec instead in that case.

Extracted the code to a separate file, since doing it all inline
became incredibly messy.