I would like plpython3u to use a virtual environment for python. I have seen some (old and not particularly clear) instructions for virtualenv at PostgreSQL PL/Python: call stored procedure in virtualenv. However I havent seen anything for python venv. Can this be done and if so, how can it be done? Thanks.
CCl.
If you only need one
venv
environment for PL/Python, you can simply modifyExecStart
in the PostggreSQL unit file to loadvenv
activate
script.Below is excerpted from the PostgreSQL 14 systemd unit file of PGDG YUM installation (My
venv
ls located at/var/lib/pgsql/plpython/
).Note that you need to copy the unit file
postgresql-14.service
from/usr/lib/systemd/system/
to/etc/systemd/system/
and executesystemctl daemon-reload
to take effect.Then you can check
venv
with thepkg_resources
module inside PL/Python anonymous block (I installpyyaml
in myvenv
environment).