Do a better job of detecting virtualenvs

This makes run-tests.sh work correctly if the user has set up a virtualenv but still has PYTHONPATH set.