I'm using Python 3.4, and having created a pyvenv, I'm looking to activate it from within a python process. With virtualenv, I used to use activate_this.py, but that appears to be gone in pyvenv.
Is there now an easy way to effectively change the current interpreter to the virtualenv interpreter? I could probably mess around with the PATH (which is what activate_this.py did), but I'd like a simpler and stabler way.
This is for use in a wsgi.py.
pyvenvand thevenvmodule don't support this out of the box. The third partyvirtualenvpackage does support this usingactivate_this.py, but that feature was not included in the built-invenvmodule.You could try to borrow a copy of
activate_this.pyfrom avirtualenvbased environment; it seems to work, though I can't swear it will be perfect (venv/pyvenvuses some magic during startup; unclear if all of it is replicated viaactivate_this.py).The
virtualenvdocs for it are out of date for Python 3 (they claim you useexecfile, which doesn't exist). The Python 3 compatible alternative would be:Nothing
activate_this.pydoes is magical, so you could manually perform the same changes without looting fromvirtualenv(adjustingPATH,sys.path,sys.prefix, etc.), but borrowing makes it much simpler in this case.