sql >> Database teknologi >  >> RDS >> PostgreSQL

Modul ikke fundet ved import af en Python-pakke i en plpython3u-procedure

Ud over andre miljøvariabler som PGDATA i et shell-script (pg_service.sh) skal du indstille PYTHONPATH='/path/to/python:/path/to/your/module'

For eksempel. kat /Users/postgres/pg_service.sh

export PGDATABASE=postgres
export PGUSER=postgres
export PGPORT=5432
export PATH=/Library/PostgreSQL/11/bin:$PATH
export PGLOCALEDIR=/Library/PostgreSQL/11/share/locale
export PYTHONUSERBASE=/Users/postgres/packaging_tutorial
export PYTHONPATH=/Library/edb/languagepack-11/Python-3.6:$PYTHONUSERBASE
pg_ctl -D /Library/PostgreSQL/11/data -l /Users/postgres/logfile $1

Start serveren:

> sudo -u postgres /Users/postgres/pg_service.sh start
waiting for server to start.... done
server started 

/Users/postgres/packaging_tutorial/example_pkg/__init__.py :

def retpy3():
    return 7/5

pg funktion:

CREATE OR REPLACE FUNCTION expy3()
RETURNS text
LANGUAGE plpython3u
AS $$
import example_pkg
return example_pkg.retpy3()
$$;

Output

psql  -c 'select * from expy3()';
 expy3
--------
 1.4



  1. MySQL group_concat() sortering efter case-sætningsværdier

  2. TinyMCE UTF-8 gemmer til MySQL-database

  3. Forskel mellem tabelfunktion og rørledningsfunktion?

  4. Tjek for tidsoverlapning i mysql