简体   繁体   English

如何升级 PL/Python 的 Python 版本

[英]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.我有一个带有 Postgres 10 服务器的 Ubuntu 18.04,运行 Python 3.5.2,PL/Python 功能运行良好。

How can I upgrade PL/Python to 3.8.0如何将 PL/Python 升级到 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我使用 pyenv 在用户“postgres”下安装 3.8.0,我检查了 python 版本已经 3.8.0,我什至将 /etc/postgresql/10/main/environment 更新为

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

But when I run PL/Python function但是当我运行 PL/Python 函数时

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

The result still 3.5.2结果还是3.5.2

PostgreSQL's plpython extension needs to be compiled against the correct python header files. PostgreSQL 的 plpython 扩展需要针对正确的 python 头文件进行编译。 I doubt the header files are binary compatible between python 3.5 and 3.8.我怀疑头文件在 python 3.5 和 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).您要么需要自己重新编译 PostgreSQL 扩展(或所有 PostgreSQL),要么找到一个包含正确编译的软件包的软件包(我怀疑您会找到)。

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.如果我愿意针对最前沿的 Python 构建自己的 Python,我可能会使用最前沿的 PostgreSQL,而不是两年前的版本。

To answer the question why.... Two Reasons:要回答为什么.... 两个原因:

  1. Python 3.5 is EOL - https://www.python.org/downloads/release/python-350/ Python 3.5 已停产 - https://www.python.org/downloads/release/python-350/
  2. Some modules need > 3.5一些模块需要> 3.5

I agree that you shouldn't "force" an upgrade if it's not supported by the Postgresql - PL/Python team yet.我同意如果 Postgresql - PL/Python 团队尚不支持,您不应该“强制”升级。

To work around this... I've seen some folks use virtual environments inside of PL/Python.为了解决这个问题...我见过一些人在 PL/Python 中使用虚拟环境。 Trying to avoid going that route if I can, rather way for direct support from the Postgresql PL/Python team.如果可以,尽量避免走那条路,而是寻求 Postgresql PL/Python 团队的直接支持。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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