Install PL/Python on Windows for PostgreSQL 12 - python

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.

Related

Oracle DPI-1047 on macOS 10.14.6 with Python 2.7.10

I am quite puzzled by the following situation: a colleague and I both use Mac OS X. I use 10.15.3, python 2.7.15, GCC 4.2.1, cx_Oracle 7.0.0 with the SQL Developer 19.1.0. She uses 10.14.6, python 2.7.10, GCC 4.2.1, cx_Oracle 7.3.0 with the SQL Developer 18.3.0.
We have a simple python script that connects to a data base via cx_Oracle. We got the usual DPI-1047 error. I followed the instructions here https://oracle.github.io/odpi/doc/installation.html#macos and with the latest 19 "Basic" version, and a bit of tweaking because of the notarization (https://github.com/oracle/python-cx_Oracle/issues/341#issuecomment-541794557) I could make it work: the .dylib files are properly picked up and the code can connect to the db.
For my colleague, the file cannot be found. We followed the exact same steps as for my computer, downloaded first the 19 then the 18 "Basic" version (naively thinking it would be related to the SQL Developer version), unzipped, and added the link to the $LD_LIBRARY_PATH variable. However, the DPI-1047 error remains to pop up.
We tried to follow previous solutions in this or other forums, but they wouldn't apply or work for us:
https://github.com/oracle/python-cx_Oracle/issues/210 (with https://www.oracle.com/database/technologies/instant-client/linux-x86-64-downloads.html#ic_x64_inst) -> the same for us except the "per step 3" part does not apply -> we do not have any .so files in the instantclient download
DPI-1047: 64-bit Oracle Client library cannot be loaded - we verified that we both use 64-bit python using python -c 'import sys;print("%x" % sys.maxsize, sys.maxsize > 2**32)', rest in this thread applies to Windows
How to fix: cx_Oracle.DatabaseError: DPI-1047: Cannot locate a 64-bit Oracle Client library - Python - there is no /usr/lib/oracle folder, neither for me nor for her, where one would need to set the version explicitly; in fact, the downloaded folder contains a soft link to the proper version of the .dylib already (we also played around with having it point to other .dylib versions)
Thank you for your help!
c.
In summary you have an issue on the 10.14.6 (Mojave) computer.
My initial thought was that you are using the OS default Python. This won't work because Apple has locked it down. From the install instructions: "Make sure you are not using the bundled Python. This has restricted entitlements and will fail to load Oracle client libraries." (I have not/cannot venture into hacking Instant Client to see if it can be made to work)
However, where did Python 2.7.10 come from? My system default is Python 2.7.16.
Don't set LD_LIBRARY_PATH. Instead my ~/lib directory has just one symbolic link:
libclntsh.dylib -> /Users/cjones/instantclient_19_3/libclntsh.dylib
All the configuration issues are due to Apple's ever tightening security requirements. Hopefully the next Oracle Instant Client release will make it easier to use.
SQL Developer is almost completely unrelated to Python cx_Oracle usage (unless you use thick-JDBC connections in SQL Developer, which is rare).
And don't follow Linux or Windows instructions on macOS!

"Unable to locate the SpatiaLite library." Django

I'm trying to make Django's SQLite3 accept spatial queries. This tutorial suggests that I add this to settings:
SPATIALITE_LIBRARY_PATH = 'mod_spatialite'
Which produces this error:
django.core.exceptions.ImproperlyConfigured: Unable to load the
SpatiaLite library extension "mod_spatialite" because: The specified
module could not be found.
I also tried doing this :
SPATIALITE_LIBRARY_PATH = r'C:\\Program Files (x86)\\Spatialite\\mod_spatialite-4.3.0a-win-x86\\mod_spatialite-4.3.0a-win-x86\\mod_spatialite.dll'
If I don't add this variable I receive this error when I migrate:
django.core.exceptions.ImproperlyConfigured: Unable to locate the
SpatiaLite library. Make sure it is in your library path, or set
SPATIALITE_LIBRARY_PATH in your settings.
Thank you..
Amusingly enough 5 days later I'm having the same issue. After a little bit of poking around I got it working:
Set
SPATIALITE_LIBRARY_PATH = 'mod_spatialite'
and extract ALL the DLL files from the mod_spatialite-x.x.x-win-x86.7z to your Python installation directory. The dll's apparently need to be in the same folder with python.exe. Also I imagine the mod_spatialite package needs to 32/64 bit according to your python installation. If you're missing some dll's, you get the same error "specified module not found" regardless of what dll file is missing, so it's a bit misleading.
Downloaded from http://www.gaia-gis.it/gaia-sins/
I used mod_spatialite stable version 4.3.0a x86 with Python 3.5.2 32-bit.
Other threads on the same issue with all sorts of answers:
Use spatialite extension for SQLite on Windows
Getting a working SpatiaLite + SQLite system for x64 c#
https://gis.stackexchange.com/questions/85674/sqlite-python-2-7-and-spatialite
On Ubuntu18.04,
adding SPATIALITE_LIBRARY_PATH = 'mod_spatialite.so'
with libsqlite3-mod-spatialite installed worked for me.
Note: The answer has mod_spatialite, while for me mod_spatialite.so worked.
This is how to install SpatiaLite (almost) inside virtualenv for Python 3:
Download cyqlite a special SQLite build with R-Tree enabled. It is required by GoeDjango.
Download mod_spatialite (Windows binaries are in the pink box at the bottom of the page) i.e. mod_spatialite-[version]-win-x86.7z
Unzip mod_spatialite files (flatten the tree and ignore the folder in the archive) into the virtuelenv Scripts folder.
This part I don't like but I not could find a workable solution without touching main Python3 installation.
Rename or otherwise backup c:\Python35\DLLs\sqlite3.dll
From cyqlite uznip sqlite3.dll file into the c:\Python35\DLLs\
Kudos: https://gis.stackexchange.com/a/169979/84121
I ran into this problem when trying to deploy GeoDjango on AWS Elastic Beanstalk. Turns out I needed to set SPATIALITE_LIBRARY_PATH = 'mod_spatialite.so' to SPATIALITE_LIBRARY_PATH = 'libspatialite.so' (installed at /user/lib64/libspatialite.so after running sudo yum install libspatialite and sudo yum install libspatialite-devel from my .ebextensions).
HOW ACTIVATE CORRECTLY SPATIALITE IN VIRTUAL DJANGO ENVIRONNEMENT IN WINDOWS OPERATING SYSTEM LIKE 7, 8, 10
I hope my answer will come to the safety of my developer friends who use Sqlite delivered by default in django to manage their geographic data by the spatialite link which is an extension also delivered by default in python (3 or +). I'm starting from the fact that you have a preconfigured virtual environment. The first thing to do is to download two zip: sqlite-dll-win32-x86-[version].zip and mod_spatialite-[version]-win-x86.7z and unzipp this in the same directory(overwrite if there are any conflicts)
Copy all previously unzipped files into your directory and paste them into your Scripts directory of your virtual environment
It all restart your pc if necessary, deactivate and reactivate your virtual environnement and code...

64-bit cx_Oracle: DLL load failed

Using Windows 2008 R2 Server. Server was completely clean. Installed 64-bit Python 3.5, 64-bit Oracle Instant Client 12c. pip installed cx_Oracle successfully. When I try to run a python script that imports cx_Oracle however, I get:
ImportError: DLL load failed: The specified module could not be found.
The instant client path is in the PATH environmental variable. I also made another system variable called ORACLE_HOME with the same instant client path.
I've double checked everything is 64-bit, and looked through SO at the many other times this has come up, and no answer has helped.
First, the environment variable ORACLE_HOME should not be set when an instant client is used. Setting it can have unintended side effects!
Second, if you used pip to install cx_Oracle that suggests you have a compiler and it succeeded in compiling the module. Check to make sure that it used the correct libraries.
Third, you can also download and install a pre-built binary from the PyPI site and see if that helps matters any. Make sure you pick the Python 3.5, 64-bit, Oracle 12c version that is listed there. The PyPI site link is here:
https://pypi.python.org/pypi/cx_Oracle

PostgreSQL unable to create plpythonu extension

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.

cx_Oracle: ImportError: DLL load failed: This application has failed

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

Categories

Resources