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

后端 未结 3 1578
谎友^
谎友^ 2020-12-30 00:47

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 kin

3条回答
  •  猫巷女王i
    2020-12-30 01:27

    For me, it was about knowing which version Python Postgres was looking at and then installing to the /local/lib directory and NOT .local directory which is not recognised in Postgres.

    In Postgres, created this function to identify the Python version it was using: .

    CREATE OR REPLACE FUNCTION python_version()
        RETURNS pg_catalog.text AS $BODY$
    
        import sys
        plpy.info(sys.version)    
        return 'finish'
        $BODY$
    LANGUAGE plpython3u VOLATILE SECURITY DEFINER
    

    Execute function using the following:

    select python_version()
    

    In Python:

    import sys
    sys.version
    

    Both the script and Python said: INFO: 3.7.3 (default, Aug 20 2019, 17:04:43)

    pip3 install placed the library into this directory: /home/username/.local/lib/python3.7/site-packages

    To make the package available to ALL users (including Postgres). I used umask:

    sudo su
    cd ~
    umask 022
    pip3 install 
    

    NOTE: The package installs in: /usr/local/lib# cd python3.7/dist-packages NOT in /usr/lib/python3/dist-packages#

提交回复
热议问题