Check the spelling
You get this message whenever you create an extension that is not available. I had the same error when running the CREATE EXTENSION plpython3u
with a spelling mistake.
Check the right Python version
One other idea is that you need the right Python version. The right version differs between Windows and Linux. Normally, you should not install the exact version yourself but rather use installers (Windows: EDB and Stack Builder --> Language pack, Linux: Follow PostgreSQL: how to install plpythonu extension.
Windows
In case of using a Windows installer, you need to install the right Python version that fits your PostgreSQL version and also set the PATH variables of Python (at least, that is needed on Windows as well, though this should be done automatically with the Python installation anyway).
On Windows, you look up C:\Program Files\PostgreSQL\13\doc\installation-notes.html
to find the needed Python version to be installed for the installed PostgreSQL version. In my case, with PostgreSQL 13:
PostgreSQL 13
Installation Notes
Welcome to the PostgreSQL 13 Installation Wizard.
Procedural Languages
The procedural languages pl/Perl, pl/Python, and pl/Tcl are included in
this distribution of PostgreSQL. The server has been built using the
LanguagePack community distributions of those language interpreters.
To use any of these languages from within PostgreSQL, download and
install the appropriate interpreters and ensure they are included in
the PATH variable under which the database server will be started. The
versions used are shown below - newer minor (bugfix) releases may also
work, but have not been tested:
Perl 5.26
Python 3.7
Tcl 8.6
Thus, Python 3.7 is needed on Windows.
I took this from a Windows PostgreSQL + plpython3u installation overview at Stack Overflow PostgreSQL 13 + Python 3.7.9 + plpython3u: 'psql: server closed the connection unexepectedly.' + 'The application has lost the database connection.'.
Linux
On Linux, I could not find such an installation-notes.html
file with the needed Python version as you find it on Windows.
Checking the Python version directly as a stored procedure in PostgreSQL with plpython3u already installed:
CREATE OR REPLACE FUNCTION return_version()
RETURNS VARCHAR
AS $$
import sys
return sys.version
$$ LANGUAGE plpython3u;
Output:
CREATE FUNCTION
Test:
postgres=# SELECT return_version();
return_version
------------------------------------------
3.8.10 (default, Jun 2 2021, 10:49:15) +
[GCC 9.4.0]
(1 row)
shows that for "PostgreSQL 13", "Python 3.8.10" gets installed. The Linux installer seems to get more attention than the Windows installer and might therefore have a more recent Python version.
Thus, in 9/2021, you need to have installed Python 3.8.10
to make this extension work. It should be automatically installed by the linux installer, though, but you can at least check with this whether you are on the right way, you should find it with:
whereis python3.8
Output:
python3: /usr/bin/python3.8 /usr/bin/python3 /usr/bin/python3.8-config /usr/lib/python3.8 /usr/lib/python3.9 /usr/lib/python3 /etc/python3.8 /etc/python3 /usr/local/lib/python3.8 /usr/include/python3.8 /usr/share/python3