How to control which Python version plpython3 uses?
Asked Answered
S

1

6

I have a postgres 11 database running on CentOS 7 and am trying to use PL/python, but need to point to a specific version of the python interpreter. I need to use python3.9 whereas it is using python3.6. I am not able to uninstall python3.6 at the moment, so was hoping to point plpython3 at my python3.9 interpreter somehow.

I have installed the package postgresql-plpython3:

sudo yum install -y postgresql-plpython3

I have created an extension in PG and can run a simple PL/python function that reports the version used:

CREATE OR REPLACE FUNCTION pyver ()
RETURNS TEXT
AS $$
    import sys
    pyversion = sys.version
    return pyversion
$$ LANGUAGE 'plpython3u';

Executing it returns this:

# select pyver();
                  pyver
-----------------------------------------
 3.6.8 (default, Nov 16 2020, 16:55:22) +
 [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]
(1 row)

On my operating systems I have the following python interpreter files, and the versions they are using:

$ /usr/bin/python3 --version
Python 3.9.6

$ python3 --version
Python 3.9.6

$ python3.6 --version
Python 3.6.8

Something within the plpython3 module seems to be hard-coded to point to my python3.6 version.

Serles answered 27/10, 2021 at 19:54 Comment(1)
Python runtime needs to match the Postgres version. Seems to me that you need to upgrade Postgres to use python 3.7 or newer.Sellars
H
2

postgresql uses an embedded python interpreter, as stated here. Changing it requires re-compiling the pl/python extension (afaik). Compilation instructions here show the relevant bits: the option --with-python and the env var PYTHON

Hopeh answered 2/2, 2023 at 16:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.