Re: How to control which Python interpreter Postgres uses?

From: Ni Ne <nineoften(at)hotmail(dot)com>
To: Wells Oliver <wells(dot)oliver(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "pgsql-admin(at)lists(dot)postgresql(dot)org" <pgsql-admin(at)lists(dot)postgresql(dot)org>
Subject: Re: How to control which Python interpreter Postgres uses?
Date: 2021-11-01 23:26:51
Message-ID: CY4PR19MB1160C888957AC39B19F65DEAB58A9@CY4PR19MB1160.namprd19.prod.outlook.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

We haven't moved to venvs yet here, so was trying to override the default Python interpreter file that postgre will use.

I did some more research and I can't see any way to adjust this behavior without compiling postgres from source, as Tom mentioned.

Here is an article from someone else with the same problem as me, solved by supplying proper configure flags during compilation:

https://forums.freebsd.org/threads/postgresql-plpython3u.67295/
[https://forums.freebsd.org/styles/freebsd/xenforo/logo.og.png]<https://forums.freebsd.org/threads/postgresql-plpython3u.67295/>
Solved - PostgreSQL, plpython3u | The FreeBSD Forums<https://forums.freebsd.org/threads/postgresql-plpython3u.67295/>
For some time now I'm trying to get Postgresql running with PL/Python and specifically plpython3u. Being new to all this, a lot of reading brought me to this: After trying with the packages to no avail I turned to databases/postgresql10-server and later to databases/postgresql10-plpython...
forums.freebsd.org

________________________________
From: Wells Oliver <wells(dot)oliver(at)gmail(dot)com>
Sent: Monday, November 1, 2021 5:08 PM
To: Ni Ne <nineoften(at)hotmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>; pgsql-admin(at)lists(dot)postgresql(dot)org <pgsql-admin(at)lists(dot)postgresql(dot)org>
Subject: Re: How to control which Python interpreter Postgres uses?

Apologies if I'm misunderstanding, but you can specify a virtual env (so any interpreter) as we did here:

CREATE FUNCTION slack (msg text)
RETURNS boolean
AS $$
hook = 'https://...'
activate_this = '/opt/python/env/bin/activate_this.py'
exec(open(activate_this).read(), dict(__file__=activate_this))
from slack_sdk.webhook import WebhookClient
import ssl
ssl_context = ssl.create_default_context()
ssl_context.check_hostname = False
ssl_context.verify_mode = ssl.CERT_NONE
webhook = WebhookClient(hook, ssl=ssl_context)
webhook.send(text=msg)
return True
$$ LANGUAGE plpython3u;

On Mon, Nov 1, 2021 at 3:06 PM Ni Ne <nineoften(at)hotmail(dot)com<mailto:nineoften(at)hotmail(dot)com>> wrote:
Would I recompile the plpython package or postgres itself?

________________________________
From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us<mailto:tgl(at)sss(dot)pgh(dot)pa(dot)us>>
Sent: Monday, November 1, 2021 4:03 PM
To: Ni Ne <nineoften(at)hotmail(dot)com<mailto:nineoften(at)hotmail(dot)com>>
Cc: pgsql-admin(at)lists(dot)postgresql(dot)org<mailto:pgsql-admin(at)lists(dot)postgresql(dot)org> <pgsql-admin(at)lists(dot)postgresql(dot)org<mailto:pgsql-admin(at)lists(dot)postgresql(dot)org>>
Subject: Re: How to control which Python interpreter Postgres uses?

Ni Ne <nineoften(at)hotmail(dot)com<mailto:nineoften(at)hotmail(dot)com>> writes:
> How can I adjust my postgres settings to tell it which Python interpreter binary to use?

You'd have to recompile plpython against the particular libpython
you want to use.

regards, tom lane

--
Wells Oliver
wells(dot)oliver(at)gmail(dot)com<mailto:wellsoliver(at)gmail(dot)com>

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Ron 2021-11-02 01:52:27 Re: How to control which Python interpreter Postgres uses?
Previous Message Wells Oliver 2021-11-01 23:08:01 Re: How to control which Python interpreter Postgres uses?