0

I am trying to run a Python script in PostgreSQL in a Windows 10 environment.

create extension if not exists plpython3u;

throws

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

How can I solve this?

Here is a log file:

`Program Files\\PostgreSQL\\14\\bin\\postgres.exe'
sys.prefix = 'C:\\edb\\languagepack-9.6\\x64\\Python-3.3'
sys.exec_prefix = 'C:\\edb\\languagepack-9.6\\x64\\Python-3.3'
sys.path = [
 'C:\\edb\\languagepack\\v2\\Python-3.9\\Lib\\encodings',
 'C:\\Python39\\python39.zip',
 'C:\\edb\\languagepack-9.6\\x64\\Python-3.3\\DLLs',
 'C:\\Python path configuration:
PYTHONHOME = 'C:\edb\languagepack-9.6\x64\Python-3.3'
PYTHONPATH = 'C:\edb\languagepack\v2\Python-3.9\Lib\encodings'
program name = 'python'
isolated = 0
environment = 1
user site = 1
import site = 1
sys._base_executable = 'C:\\Program Files\\PostgreSQL\\14\\bin\\postgres.exe'
sys.base_prefix = 'C:\\edb\\languagepack-9.6\\x64\\Python-3.3'
sys.base_exec_prefix = 'C:\\edb\\languagepack-9.6\\x64\\Python-3.3'
sys.platlibdir = 'lib'
sys.executable = 'C:\\edb\\languagepack-9.6\\x64\\Python-3.3\\lib',
 'C:\\Program Files\\PostgreSQL\\14\\bin',
]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'
mkrieger1
  • 19,194
  • 5
  • 54
  • 65
  • Seems to be caused by Python not being able to find the module in its PYTHONPATH or PYTHONHOME environment variables: https://stackoverflow.com/questions/38132755/importerror-no-module-named-encodings - seeing multiple Python versions (both 3.3 and 3.9 mentioned also seems to be a bit weird) - verify that the variables as given in PYTHONHOME and PYTHONPATH makes sense (and point them possibly to the same version. – MatsLindh Jun 13 '23 at 20:50
  • Make sure you're using the correct Python version for your Postgres version as well, as shown in https://stackoverflow.com/questions/47907232/could-not-load-library-plpython3-dll - you can use the dependency walker to see which one is required (check install notes as well): https://stackoverflow.com/questions/21001890/installing-plpythonu-on-windows – MatsLindh Jun 13 '23 at 20:51
  • You'll have to do due diligence. First, check if the file exists. If it does exist, use a DLL dependency resolution software (not shipped with Windows, as far as I know) to see if all the libraries it is linked with can be resolved. [Edit] the question and add your findings there. – Laurenz Albe Jun 14 '23 at 06:22

0 Answers0