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.

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. Commented Jul 25, 2022 at 15:50

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.