2

I am writing function in postgres in python using the PL/Pythonu extension in postgres. I would like postgres to use my virutal environment (I am using virtualenv) instead of the global install. How do I go about doing this?

Barry Steyn
  • 1,563
  • 3
  • 19
  • 25

2 Answers2

4

As it turns out, one must add the path to where the libraries are found to the PYTHONPATH environment variable in postgres. Don't forget to quote your value eg:

PYTHONPATH='path to libraries'

Barry Steyn
  • 1,563
  • 3
  • 19
  • 25
  • As described in http://stackoverflow.com/q/9586331/217844, this only seems to work in certain OSs. Ideally, Postgres should have a VIRTUALENV configuration setting. – ssc Jul 08 '12 at 21:48
2

Answered over at https://stackoverflow.com/a/24892335/5430

tl;dr - exec activate_this.py inside plpython function will set python interpretor for the life of the postgresql session.

Community
  • 1
  • 1
reedstrm
  • 372
  • 1
  • 9