I'm trying to write a function in PostgreSQL on Windows with a Python script in the body and i'm running into an error message when trying to create the plpythonu extension. The command I'm running is:
CREATE EXTENSION plpythonu;
Which produces the following error message:
ERROR: could not access file "$libdir/plpython2": No such file or directory
SQL state: 58P01
I also tried running:
CREATE EXTENSION plpython3u;
which results in this error:
ERROR: could not load library "C:/Program Files (x86)/PostgreSQL/9.2/lib/plpython3.dll": The specified module could not be found.
SQL state: 58P01
The plpython3.dll file exists at this location, but apparently is missing some critical dependency. I've searched everywhere and found nothing helpful on this. I have both Python 2 and 3 installed on the machine...
The newest (9.4 or later) binary installations from EnterpriseDB contain only plpython3u.dll. In versions 9.4 to 9.6 I had to install python 3.3 to get plpython3u run.
You can check which version of Python is needed by plpython3u.dll using Dependency Walker.
A full answer can be found:
https://postgresrocks.enterprisedb.com/t5/PostgreSQL/unable-to-install-pl-python-extension/m-p/4090
It assumes you have used stackbuilder to install the edb language pack.
Do check the commands for correctness in your installation.
E.g. path to postgresql data, install path of edb and python version.
When you use depency walker (depends.exe), only pay attention to the pythonxx.dll. With older PG versions, this may or may not agree to the version installed by the EDB languages package. For version 10.7, version 3.4 Python is required. For windows, the later 3.4 Python versions do not appear to have a msi installer. You may have to install 3.4.4, or try to upgrade PG 10 to the latest version (10.11) first. This version requires python 3.7, so then you can use the EDB download.
But the python version may already exist and be found.
could not load library plpython3.dll (here on stackoverflow) was somewhat close, but did not detail the environment vars needed.
the solution proposed does not require you to change env vars permanently, which is a great help when using several python installations.
Related
I'm running clang on mac to compile a c file created by running a very simple program through cython, but the compiler always give me a "Python.h not found" fatal error. I've tried every solution I could find, reinstalling python 3.9, using the -I/path/to/headerfile method, and rewriting the include statement in the code to contain the full filepath, but nothing has worked. When I do include the full filepath, I get fatal error: 'cpython/initconfig.h' file not found. What could the issue possibly be, and how would I fix it? The program itself works fine in the standard python interpreter, pyinstaller, and nuitka.
Today I needed to embed Python into a C application developed on XCode with Clang compiler, and I've met the same problems and solved them. Let me share the tips:
1. Python not found error
You should install a Python framework to your MacOS, and attach it into Frameworks and Libraries project settings tab. Also, specify it's path in Framework Search Paths inside Build Settings tab if XCode hasn't done it automatically.
2. Undefined symbols / Implicit declaration errors
Verify you're using a modern version of Python framework. Versions prior to 3.6 had different ABI which leads to the mentioned errors.
3. cpython/initconfig.h file not found
Versions prior to ~3.9 had some header inclusion problem for the cpython/initconfig.h file (issues 40642, 39026).
Check the builds of Python that your OS currently has. I found Pythons installed in the following paths:
# Default 2.7 MacOSX installation is here
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/
/Applications/Xcode.app/Contents/Developer/Library/Frameworks/
/Library/Frameworks/
Or install a recent Python version. I recommend using "universal binary" build, see the docs.
I've been working on FHIR for a project and we are using PostgreSQL as a database. While reading docs, I've come to know about PL/Python and decided to give it a shot but I am unable to install the python extension.
When I run the command CREATE EXTENSION pypthon3u; I get the following error
Could not load library "C:/Program Files/PostgreSQL/12/lib/plpython3.dll": The specified module could not be found.
I've checked this SO answer but it couldn't help.
My PostgreSQL version: PostgreSQL 12.2, compiled by Visual C++ build 1914, 64-bit
Installed Python version: 3.7.7 (64 Bit)
OS Info: Windows 10 Enterprise Version 1909 OS Build 18363.657
For me, it looks like incorrect version of Python but I'm installing python 3.7.* version against which PostgreSQL is compiled as specified in doc\installation-notes.html inside the install directory.
Any help will be appreciated.
Even if you use the EDB installer's Stack Builder to install Python, you still have to follow the instructions to "ensure they are included in the PATH variable under which the database server will be started". I had to do this at the system level, as I can't find a way to set the PATH for individual services.
And then you also need to set PYTHONPATH as well, which seems to be undocumented.
So I ended up adding c:\edb\languagepack\v1\Python-3.7 to PATH and creating PYTHONPATH with c:\edb\languagepack\v1\Python-3.7\Lib.
I had to add directory containing plpython3.dll do system/user variables (windows).
I was trying the same. Though I am no expert and my errors were a bit different, here are a few things to check:
under share\extension\, there should be plpython3u.control and plpython3u--1.0.sql to be able to do CREATE EXTENSION plpython3u;
ensure you are not having any typo in the command above.
under lib\, there should be a plpython3.dll. This one is possibly created after the above step.
make sure lib\ is in your PATH.
PYTHONHOME should be set in either system/user environment, or should be set before the server start. It seems the version is not as much important as having this name set. plpython3.dll seems to look for a python39.dll but I could use it with a 3.8 installation.
I used a zipped version of Postgres, so the following is my way to run the server.
set PATH=%PATH%;d:\pgsql\bin\;d:\pgsql\lib\
set PYTHONHOME=c:\DevTools\Python\Python38
pg_ctl -D d:\pgsql\pgdata -l logfile start
PS: without PYTHONHOME, the server crashes. the server itself or psql restarts the server but I am not sure about pgAdmin.
I have been trying to get SCons working now for quite a time, but didn't succeed yet. Before everything else: I'm running Windows 7 x64.
I have firstly installed Python 2.7.11 in C:\Software\Python27 and added both that directory as C:\Software\Python\Scripts to
the system path (for all users, that is). Then I installed SCons in C:\Software\Python27\Lib\site-packages\scons-2.4.1, and
the scripts in the previous mentioned scripts-directory (the directories which the SCons installation msi defaults to).
And now when I try to run SCons I get this error message:
Import failed. Unable to find SCons files in:
...
ImportError: No module named SCons.Script
As a user I really don't have any idea where the error comes from, other than that SCons can't resolve it's own imports.
I got it working by creating though by creating a new folder: C:\Software\Python27\Scripts\scons-local and moving the
contents of the SCons installation folder (...\Python27\Lib\site-packages\scons-2.4.1) to the newly created folder. But this
gives me a syntax error:
I found here that this error is due to my Python version not supporting conditional expressions, because this kind of
expressions are supported from Python 2.4 and higher. The thing is though that I am using Python 2.7.11, and thus I shouldn't get
this error.
Some help would be highly appreciated, thanks in advance!
The windows installer is no longer supported.
The best way to install SCons is now via pip
so:
python -Mpip install SCons
Note you will need Python 3.5 or newer (though at this point I'd suggest 3.10 or newer)
Here's what I did:
I'm on Windows XP SP3
I already had Python 2.7.1 installed.
I downloaded instantclient-basic-nt-11.2.0.3.0.zip, unzipped it, and put it in C:\Program Files\Oracle\instantclient_11_2.
I added this path to the Windows Path environment variable.
I created a new environment variable ORACLE_HOME holding this path as its value.
I installed cx_Oracle-5.1.2-11g.win32-py2.7.msi.
And on running import cx_Oracle all I get is
Traceback (most recent call last):
File "<string>", line 2, in <module>
ImportError: DLL load failed: This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem.
I obviously uninstalled / reinstalled cx_Oracle a couple of times but really nothing seems to help. Could anyone please provide a clue how to fix this?
UPDATE
I ran Dependency Walker and it comes up with a lot of trouble. However, the first missing .dll (msvcr80.dll) is actually present in C:\WINDOWS\WinSxS\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.91_x-ww_0de56c07.
OK, what finally solved the problem (not sure whether all steps are necessary and no idea why exactly this and only this worked so far):
Download and unzip version 12 from here.
Add "ORACLE_HOME" as a Windows environment variable and set its value to ...\instantclient_12_1, (not its containing folder!).
Add this same path to the "Path" environment variable.
Only now install cx_Oracle.
To help other people with the same problem:
This error tells about 32-64 bit mismatch between some DLL while importing module. Possibilities are:
Different architecture of Python and cx_Oracle (less probable since cx_Oracle installer on Windows warns you if appropriate Python was not found).
Different architecture of cx_Oracle libraries and oci.dll (more probable).
Keep in mind that cx_Oracle uses standart Oracle client (at OCI level), which must be installed on your machine. It searches for oci.dll in several places, including PATH. If it finds oci.dll of wrong version of the client, the error appears.
In case you get this error, check path list in the PATH environment variable. It is likely to contain path to BIN folder of wrong version of Oracle client. If you have several clients, specify in the PATH the appropriate one, or install the appropriate client.
NOTE: ORACLE_HOME does not have an effect for cx_Oracle. In my case only changing of PATH helped. I think the Ruben's solution works because of item 3 ('Add this same path to the "Path" environment variable').
I am using python35 64 bit and oracle express on win 7 (64 bit).
I installed cx_Oracle using pip3 (pip3 install cx_Oracle) instead of downloading the installer from pypi.
I faced the same problem.
I solved it by following above guidelines, but instead of 32 bit client, I downloaded the 64 bit version of the instant client (instantclient-basic-windows.x64-11.2.0.4.0.zip) from http://www.oracle.com/technetwork/topics/winx64soft-089540.html.
I then extracted it to c:\oraclexe. And added these environment variables
set ORACLE_BASE=C:\oraclexe
set ORACLE_HOME=C:\oraclexe\app\oracle\product\11.2.0\server
set PATH=C:\oraclexe\instantclient_11_2;%PATH%
And ran my django migrate commands:
python manage.py migrate
It worked excellent
Easy way:
Make sure you have installed cx-Oracle, I have cx_Oracle-5.1.3-11g.win32-py2.7.exe
Download, unzip instantclient_12_1 and move it to C:\Python27
Add environment variable C:\Python27\instantclient_12_1
Restart your computer
Same ImportError occured for setup of:
Windows 10 x64
Oracle Instant Client 12_1 x64
Python 2.7.11 x64
cx_Oracle cx_Oracle-5.2-12c.win-amd64-py2.7
I solved it copying msvcr100.dll file into <oracle_instant_client_dir>
Had this issue also, and it seems importing cx_Oracle (at least as of 5.1.2) will fail (with the same error) if you have any invalid/unreachable UNC paths in front of Oracle in the PATH environment variable.
Fixing the UNC path (which was unrelated to Oracle) resolved the problem.
If you're using conda as a package manager, one way to overcome the DLL issue it to install oracle-instantclient by doing a conda install oracle-instantclient. This fixed the dependency which I couldn't fix by manually installing Oracle's instant-client.
As is the second time I came to this question, I feel the need to post what I did:
I'm using:
Win 8 64 bits
Python 2.7
I had no success installing Python and cx_Oracle 64 bits.
It only worked when I tried 32 bits versions and followed #rob answer instructions
I had same issue with DLL load failed on my Windows machine.
installed oracle client, set variables, ran cx_Oracle-5.1.3-11g.win32-py2.7.exe file.
however when I installed cx_Oracle with easy_setup it fixed the problem.
C:\Python27\Scripts\easy_install.exe cx_Oracle-5.1.3-11g.win32-py2.7.exe
Steps I have followed :
Downloaded the smart client instantclient-basic-windows.x64-12.1.0.2.0.zip
Extracted and copied to #your directory#\instantclient_12_1
Above directory contains dll's
Append the PATH variable with #your directory#\instantclient_12_1 and created env variable ORACLE_HOME= #your directory#\instantclient_12_1
Download and install cx_Oracle-5.2.1-11g.win-amd64-py2.7.exe
Open idle type import cx_Oracle
if you're using Anaconda on Windows try:
conda install cx_oracle
on your cmd
-> this
I know this is an old post, but I had this problem today and none of the solutions worked. I figure this could work for others with the same problem as of now.
Python version : 2.7.15 (64 bits)
cx_Oracle version : 6.4.1
Oracle Instant Client : 18.3
I kept getting the following error even though I followed evry steps in the correct order :
cx_Oracle.DatabaseError: DPI-1047: Oracle Client library cannot be loaded
I solved it by downgrading my Oracle Instant Client version to 12.1
Having some problems with Gdal installation with python 2.7 on Windows 7 32bit. I am running MSVC 2010. I have followed the instruction from the blog website
http://cartometric.com/blog/2011/10/17/install-gdal-on-windows/
The installation is fine. At the end of it, I am able to run ogr2ogr in the MS-DOS and have gotten the similar screen as listed in the blog.
However, when I am trying to use the command "import osgeo" on the Python IDLE GUI shell. A series of error message is released, reading like the following
"DLL error:.........."
I believe that this might mean that the python binding is of wrong version. I have cleared up my installation by removing the following: Python-Gdal binding, Gdal, Python 2.7
After removing them, I have retried my installation with Python 3.2.3 instead and loaded the Gdal package and python binding accordingly. However, the same error returns.
Is there any intermediate steps that I could take to verify the installation. Any other advice I could have to have the bindings installed? Or is my reinstallation method correct?
I have tried to install FWTools too. It doesnt seem to work either. I have run the Python shell from EV-shell and type in "import osgeo". Have gotten the message "no module exist...."
Thanks
Get the precompiled gdal from here:
http://www.lfd.uci.edu/~gohlke/pythonlibs/#gdal
I have some other notes on setting up postgres and postgis 2.0 here if you need it:
http://monkut.webfactional.com/blog/archive/2012/5/2/using-django-14-with-gdal-19-and-postgis-20/