Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install 3rd party module for postgres pl/python?

I need to import a 3rd party module inside my pl/python function. It seems pl/python uses an internal python that does not have any 3rd party modules.

I get this kind of error:

ERROR:  PL/Python: PL/Python function "to_tsvector_luc" failed DETAIL:  <type 'exceptions.ImportError'>: No module named lucene  ********** Error **********  ERROR: PL/Python: PL/Python function "to_tsvector_luc" failed SQL state: XX000 Detail: <type 'exceptions.ImportError'>: No module named lucene 

How do I install the module into pl/python, so that I can import it from inside my stored procedure code?

like image 449
kakarukeys Avatar asked Nov 07 '11 02:11

kakarukeys


People also ask

Does Postgres support Python?

Installation. The PostgreSQL can be integrated with Python using psycopg2 module. sycopg2 is a PostgreSQL database adapter for the Python programming language.


1 Answers

pl/python has access to the all the modules that the normal Python interpreter would have as long as they are in the $PYTHONPATH on the server (and the user that runs the postgres service). Does import lucene work if you run it in the Python interpreter on the server?

If your module is installed somewhere else (e.g. not dist-packages etc.), then you would need to edit your /etc/postgresql/9.1/main/environment (adjust to your PostgreSQL version) file on the server and add something like PYTHONPATH='<path to your module>'.

like image 67
Adrian Avatar answered Oct 08 '22 20:10

Adrian