简体   繁体   中英

How to upgrade Python version for PL/Python

I have a Ubuntu 18.04 with Postgres 10 server running Python 3.5.2, PL/Python function works very well.

How can I upgrade PL/Python to 3.8.0

I used pyenv to install 3.8.0 under user 'postgres', I checked python version already 3.8.0, I even updated /etc/postgresql/10/main/environment to

PYTHONPATH= '/var/lib/postgresql/.pyenv/shims/python3'

But when I run PL/Python function

CREATE FUNCTION ptest ()
  RETURNS text
AS $$
  import sys
  return sys.version
$$ LANGUAGE plpython3u;

The result still 3.5.2

PostgreSQL's plpython extension needs to be compiled against the correct python header files. I doubt the header files are binary compatible between python 3.5 and 3.8. You will either need to recompile the PostgreSQL extension (or all of PostgreSQL) yourself, or find a package which ships the correctly compiled packages (which I doubt you will find).

The simple answer is, "don't do this". Why do you want to do this? If I were willing to build my own against a bleeding edge python, I would probably be doing it with a bleeding edge PostgreSQL, not the two year old version.

To answer the question why.... Two Reasons:

  1. Python 3.5 is EOL - https://www.python.org/downloads/release/python-350/
  2. Some modules need > 3.5

I agree that you shouldn't "force" an upgrade if it's not supported by the Postgresql - PL/Python team yet.

To work around this... I've seen some folks use virtual environments inside of PL/Python. Trying to avoid going that route if I can, rather way for direct support from the Postgresql PL/Python team.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM