I have added all of the details I could find, with all of the links, and there is no way to get plpython3u to work on Windows in PostgreSQL 13, it seems.
Better do not read through this long question and rather just jump to the answer: not to use Windows PostgreSQL when you need plpython3u. This question has been opened long enough, no solution in sight.
Perhaps a higher PostgreSQL version for Windows will solve this, then please answer.
Spin-off
This is a spin-off from
Can't “install” plpython3u - postgresql and all of its comments
and from
PosgreSQL 11 lost connection when i'm trying to create function with plpython3u [WIN10, pgAdmin4 3.5].
Steps of errors and solutions up to now
I have taken these steps which were totally scattered across Stack Overflow:
Step 0
If you run a sql that uses the language plpython3u without it being installed, you get
ERROR: language "plpython3u" does not exist HINT: Use CREATE
EXTENSION to load the language into the database.
SQL state: 42704
Related:
Step 1
At error
ERROR: could not load library "C:/Program Files
(x86)/PostgreSQL/13/lib/plpython3u.dll": The specified module could
not be found.
SQL state: 58P01
look up C:Program FilesPostgreSQL13docinstallation-notes.html
to find the needed Python version to be installed for the installed PostgreSQL version.
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 the 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.
Credits go to:
Related:
Step 2
Install Python version using the webinstaller of Python Releases for Windows
The most recent sub-version 3.7.10 does not have any files in the list of stable releases and I am too lazy to install Python from source on Windows. The source code of v3.7.10 is available here Looking for a specific release?, for anyone who wants to try):
Python 3.7.10 - Feb. 15, 2021
Note that Python 3.7.10 cannot be used on Windows XP or earlier.
No files for this release.
Explanation copied from How to build Python 3.4.6 from source?
The Python 3.7 branch is in security fixes only mode. This means that
only security fixes will be accepted on this branch, no more
non-critical bug fixes. New releases on this branch are source-only,
no binaries will be provided.
See the official
announcement.
If you really need a python 3.7.10 binary for windows, you will have to
compile it yourself.
Cannot install plpython for postgres 12 recommends to install a specific version from source:
you want to use a specific python version > use source and compile it
Again, since I am lazy, I take the most recent stable release of 3.7, which is sub-version 3.7.9, and this should be no problem following the remark, as you seem to be free to choose the sub-version:
Try version python-3.4.0.amd64 for windows 64bit or other versions
from this Python 3.4.0 downloads Link
From: could not load library plpython3.dll
As I said, I am too lazy to take the effort of compiling the binaries of v3.7.10 on Windows when v3.7.9 is available, thus:
Python 3.7.9 - Aug. 17, 2020
Note that Python 3.7.9 cannot be used on Windows XP or earlier.
Download Windows help file
Download Windows x86-64 embeddable zip file
Download Windows x86-64 executable installer
Download Windows x86-64 web-based installer
Download Windows x86 embeddable zip file
Download Windows x86 executable installer
Download Windows x86 web-based installer
I install "Download Windows x86-64 web-based installer" (side-note: you cannot change the installation path, they seem to force you to use this; to reach it quickly, in Windows Explorer, type in the path %appdata% --> go to parent folder "appdata" --> then to "local" --> "programs" --> "python" to quickly get there) and check the box for adding the PATH variables as well.
You will have a new entry in your user environment variable "PATH" and you may check this, but you do not need to:
C:UsersMY_USERAppDataLocalProgramsPythonPython37Scripts
and
C:UsersMY_USERAppDataLocalProgramsPythonPython37
Credits go to:
Step 3
When executing
CREATE EXTENSION plpython3u;
in the query tool of PostgreSQL pgAdmin4, I get the error:
could not load library "C:/Program
Files/PostgreSQL/13/lib/plpython3u.dll": The specified module could not
be found
Go to your Python 3.7 installation folder, in my case
C:UsersMY_USERAppDataLocalProgramsPythonPython37
and copy "python37.dll" from there to
C:WindowsSystem32
by confirming that you have admin rights.
Now execute again and it will work:
CREATE EXTENSION plpython3u;
Credits go to:
Related questions:
Step 4 (optional)
SELECT * FROM pg_extension;
Output:
old | extname | extowner | extrelocatable | extversion | extversion | extconfig | extcondition
"13428"| "plpgsql" | "10" | "11" | false | "1.0" | [null] | [null]
"16776"| "plpython3u" | "10" | "11" | false | "1.0" | [null] | [null]
And another check with:
SELECT * FROM pg_language;
Output:
lanname | lanowner | lanispl | lanpltrusted | lanplcallfoid | laninline | lanvalidator | lanacl
------------+----------+---------+--------------+---------------+-----------+--------------+--------
internal | 10 | f | f | 0 | 0 | 2246 |
c | 10 | f | f | 0 | 0 | 2247 |
sql | 10 | f | t | 0 | 0 | 2248 |
plpgsql | 10 | t | t | 12279 | 12280 | 12281 |
plpython3u | 10 | t | f | 40963 | 40964 | 40965 |
(5 rows)
Now the available extensions (that is, all possible extensions that can be installed) also show installed_version
= 1.0
for the plpython3u extension:
SELECT * FROM pg_available_extensions WHERE name LIKE '%python%' ORDER BY name;
Output:
or the output when running the same in psql:
name | default_version | installed_version | comment
------------+-----------------+-------------------+-------------------------------------------
plpython3u | 1.0 | 1.0 | PL/Python3U untrusted procedural language
(1 Zeile)
<