(All of this code tested in Enterprise DB PostgreSQL 9.4 Beta 1 and Python 3.3)
As of Virtualenv 1.3 (https://pypi.python.org/pypi/virtualenv) (and excluding Python 3.4's venv) there is an activate_this.py file within a virtualenv package that allows activation of a virtual environment within an embedded version of Python (like PostgreSQL's PL/Python). A Python 2/3 compatible version looks like this:
exec(open('/Some/VirtualEnv/Directory/myvirtualenv/bin/activate_this.py').read(),
dict(__file__='/Some/VirtualEnv/Directory/myvirtualenv/bin/activate_this.py'))
Where /Some/VirtualEnv/Directory
is a directory and myvirtualenv
is the name of the virtual environment in use. On Windows replace bin
with Scripts
.