When I call a PostgreSQL PL/Python stored procedure in my Python application, it seems to be executed in a separate process running as user postgres
. So far, this only had the side effect that I had to make my logfile writable for both myself and the database user, so application and stored procedure can both write to it.
Now however, I started using virtualenv
and added a number of .pth
files to my ~/.virtualenvs/virt_env/lib/python2.7/site-packages/
folder that add the paths to my modules to the Python path.
When the stored procedure is executed, user postgres
is not in the same virtual environment as I am, so the stored procedure does not find my modules. I can modify PYTHONPATH
in the global PostgreSQL environment, but I have to change that every time I switch virtual environments - which is kinda against the purpose of virtualenv...
How can I extend the Python path for stored procedures ?
UPDATE:
A similar question has been asked and the resolution there was to modify the PYTHONPATH environment variable in Postgres; however, it seems that there is no standard way to specify environment variables for PostgreSQL; at least, it is not a viable solution on Mac OSX.