3

I have installed PostgreSQL Server 9.6.0 and Python 3.4.2 on Windows 2012 R2 Server.

I copied plpython3.dll to C:/Program Files/PostgreSQL/9.6/lib/

The in PostgreSQL I try running this command: CREATE EXTENSION plpython3u;

And I receive this message:

ERROR: could not load library "C:/Program Files/PostgreSQL/9.6/lib/plpython3.dll": The specified module could not be found.

Under this folder: C:\Program Files\PostgreSQL\9.6\share\extension there are plpython3u files.

How can I get PostgreSQL to recognize this Python 3 extension?

Thanks!

A.G.
  • 2,089
  • 3
  • 30
  • 52

5 Answers5

7

Copy the python34.dll file to c:\windows\system32 and name the copy python33.dll

The create language plpython3u should then work without a problem.

questionto42
  • 7,175
  • 4
  • 57
  • 90
Gert van Biljon
  • 371
  • 3
  • 6
  • 3
    Similar for me. I installed postgress 11.2 with edb posgress language pack - with python, tcl, etc, and everything was in the path. I also had to copy python36.dll from C:\edb\languagepack-11\x64\Python-3.6 into C:\Windows\System32 – monkeyhouse Mar 29 '19 at 03:30
  • 1
    I had to copy python37.dll, for postgres 10. Otherwise extension creation fails. – djm Dec 16 '20 at 22:37
2

Exactly the same situation I faced with Postgres 9.6 Windows 10. PL/Python3U would not get through.

Worked around it:

Installed Python34 64bit Windows 10 version. Copied Python34.dll to c:\windows\system32 as Python33.dll and it worked.

BB23850
  • 109
  • 1
  • 11
  • This answer (which is actually a comment) helped me understand that the python33.dll needs to be copied *from* the Python installation *to* the "System32" folder. The accepted answer was not clear about this saying `Make a copy of the python34.dll file in c:\windows\system32 and name the copy python33.dll`, I thought by mistake that the file is expected to be already *in* that "System32" folder and then needs to be copied as another name *in that same folder*. – questionto42 Jun 05 '21 at 11:08
  • @questionto42 this is simple. The file name and path is store in the plpython3.dll. So you need exactly the same path and the same name. But change this name as an impact to other product because you declare a v3.4 is a v3.3 for system. – GeoStoneMarten Jun 10 '21 at 09:57
  • @GeoStoneMarten It was not about that. I was only confused by "Make a copy ... in". I thought the same folder (system32) was meant. That is why I edited the other anser now to say "copy from ... to ...". The rest was clear anyway. – questionto42 Jun 11 '21 at 12:28
1

The information is in Makefile of source installation package

We need libpython as a shared library. In Python >=2.5, configure asks Python directly. But because this has been broken in Debian for a long time (http://bugs.debian.org/695979), and to support older Python versions, we see if there is a file that is named like a shared library as a fallback.

for python windows:

ifeq ($(PORTNAME), win32)

    pytverstr=$(subst .,,${python_version})
    PYTHONDLL=$(subst \,/,$(WINDIR))/system32/python${pytverstr}.dll

So the write answer is:

  • WINDIR is : C:\Windows
  • pytverstr is use in makefile has a parameter to define version of python
  • PYTHONDLL is the location of dll

To check version of my installation, I open plpython3.dll located in C:\Program Files\PostgreSQL\9.4\lib (change path with your environnement)

With Notepad++ and search PyUnicode_AsUTF8String the python dll version is visible in last word (in my case python33.dll)

check your installation to choice the good installer of python

SELECT version();

PostgreSQL 9.4.15, compiled by Visual C++ build 1800, 64-bit

So I need install Python 33 in 64bit

edit 2020-10-02

There is also all of these informations in doc of binary ..pgsql\doc\installation-notes.html look at title Procedural Languages

edit 2021-06-11

After install the good version of Python on your system you need copy it to C:\Windows\System32

Replacing the version of python with an old name is not a good solution because you can have librairie it not work with this version. Do that if you know risks. So if you want a newest version of python for plpython, compile it or check edb compilation to check if it contains what you need. You can ask EDB for this information.

GeoStoneMarten
  • 533
  • 1
  • 7
  • 19
  • I also get this error after having installed the right Python version together with settgin the two PATH variables. This answer is only worthwhile because it explains a bit of the background of the python33.dll. Not because of its recommendation to install the right Python version, since that alone does not fix the error reported in the question. – questionto42 Jun 05 '21 at 11:01
  • @questionto42 please don't read between the lines. All off Postgresql is paquage and build with specific version of product and i explain what path is use. So I don't speak about PATH and set python in PATH isn't a good practice. when you have lot of product who use diferent version of python environnement. Postgresql recommand to set specific python path in a start script. Set the PATH of windows as no impact beacause the path is declared staticaly when it's build. If you want specify other path you can read the docs of python and postgresql – GeoStoneMarten Jun 10 '21 at 09:30
  • @questionto42 for override paths you need to know that https://www.postgresql.org/docs/9.6/plpython-envar.html and for environnement python variables https://docs.python.org/3/using/cmdline.html#environment-variables – GeoStoneMarten Jun 10 '21 at 09:36
  • You are right, I do not know why I thought you were reporting about setting the PATH. I do not see any setting of PATH variables in your answer now, thus, my fault. Instead, you explain in detail *why* this copying and renaming needs to be done manually which is of value of course, upvote. – questionto42 Jun 11 '21 at 12:31
  • Now I know what I meant to criticize. You mention "check your installation to choose the right installer of python" and "There is also all of this information in doc of binary ..pgsql\doc\installation-notes.html look at title Procedural Languages". BUT: the right python version does not help fixing the issue here, since I had the right version installed anyway, before I found this question. The way to solve the issue in question was to add the dll file. Which is just the first half of your question. – questionto42 Jun 11 '21 at 12:48
  • @questionto42 ok i do an edit on my response to include the needed path. I haven't copied response of other. I just explain why that's the way it is. – GeoStoneMarten Jun 11 '21 at 13:20
  • I do not think you need to add the needed path, the accepted answer is enough. Anyway, I have installed PostgreSQL 13 with Python 3.7 and the python37.dll in system32 (no renaming needed) and the installation works, but then the database crashes as soon as I use plpython3u, that is why I opened a new question at [PostgreSQL 13 + Python 3.7.9 + plpython3u: 'psql: server closed the connection unexepectedly.' + 'The application has lost the database connection.'](https://stackoverflow.com/questions/67852675/postgresql-13-python-3-7-9-plpython3u-psql-server-closed-the-connection-u). – questionto42 Jun 11 '21 at 13:42
  • It worked for me. PostgreSQL 15 on windows. It said `Python 3.9` inside `C:\Program Files\PostgreSQL\15\doc\installation-notes.html`, but `C:\Program Files\PostgreSQL\15\lib` was looking for `python310.dll`. *I HAVE NO IDEA WHY*. I used the `python310.dll` name and it worked. – winwin Apr 04 '23 at 11:58
  • @winwin The version is clearly described in the DLL. As I mentioned earlier, all you need to do is open the DLL from the PG 15.2 [binaries archive](https://www.enterprisedb.com/download-postgresql-binaries) (**plpython3.dll**) with a text editor to see which version is actually used in the compilation. Therefore, the documentation is not up to date. You can see line 587 of the file with the following description : `PyUnicode_FromStringAndSize ¤PyUnicode_FromString gPyUnicode_AsUTF8String python310.dll ` – GeoStoneMarten Apr 15 '23 at 20:46
0

plpython3.dll in the official package is built against python 3.3, not python 3.4. What it expect is python33.dll in system32 folder. You need to install python 3.3 for your system.

Since py33 has been phased out, you may soon get frustrated, due to lack of pre-built binary package, lxml, pyzmq etc all needs to be built from source. If you need any binary module, make sure you have a correctly set up compiler.

Ben
  • 1,133
  • 1
  • 15
  • 30
0

This may be helpful, I have struggled a lot with this. For me only worked when I installed the right version of python and added paths to environment variables. I am not sure if python 3.4.0 would be the right version for PostgreSQL Server 9.6.0 but it worked fine with PostgreSQL Server 10.0.

Try version python-3.4.0.amd64 for windows 64bit or other versions from this Python 3.4.0 downloads Link

Environment variables to add:

C:\Python34\Scripts C:\Python34\

Andrius V.
  • 134
  • 1
  • 8
  • Downvote. This does not fix it. The error reported in the question occurs not before, but after having installed the already right Python version and with the two PATH variables already set. I have just tested this. You say yourself that it just *may be helpful*, but it does not answer the question. It is worth a comment, not an answer. – questionto42 Jun 05 '21 at 10:53