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

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

Related

Install PL/Python on Windows for PostgreSQL 12

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.

"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

Python module "cx_Oracle" module could not be found

I recently installed cx_Oracle module on my machine, in order to connect to a remote Oracle database server. (I have no Oracle client at my side).
Python: Version 2.7 x86
Oracle: Verision 11.1.X x64
Cx_Oracle:Verion-5.1.2-11g.win32-py2.7
Then everytime I run my script, it fails and print the following message:
ImportError: DLL load failed: The specified module could not be found.
I found a related post at Here, so I am wondering if I anyway have to have an Oracle client at my side where the python script is invoked.
Can anyone help me out? Thanks in advance.
# - This import requires appropriate oraocciXX.dll to be available in PATH (on windows)
# (Probably LD_LIBRARY_PATH or LD_LIBRARY_PATH64 on POSIX)
# where XX is the oracle DB version, e.g. oraocci11.dll for Oracle 11g.
# - This dll is part of the Oracle Instant client pkg available here:
# http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html
# - Also ensure that python, cx_Oracle and Oracle Client are of same arch (32 or 64-bit)
#
import cx_Oracle
You can find out arch (32 or 64-bit) for:
python by just running the python in interactive mode on command line.
cx_Oracle: look at the name of downloaded file.
Oracle Client:
run the sqlplus that's part of your client package
start Task Manager and see if sqlplus.exe has "*32" next to it (=32 bit) or not (=64 bit)
if you don't have sqlplus, use dumpbin /headers oraocciXX.dll
If you're using POSIX you probably would already know. Use file oraocciXX.so
Finally if you still don't understand here is really for dummies instructions:
Ensure you've installed 32-bit versions of python, cx_Oracle and Oracle Instant Client. These could also be 64-bit, but must be same for all 3. Can not mix and match. Links:
Oracle Instant Client Lets say it's installed in C:\ProgFiles\OraClient\11_2
cx_Oracle
Python
Windows:
set PATH=%PATH%;C:\ProgFiles\OraClient\11_2
POSIX (Linux/Unix/Solaris...) <-- Untested..
export LD_LIBRARY_PATH=/path/to/your/32bit/oraocciXX.so
(64 bit) export LD_LIBRARY_PATH64=/path/to/your/64bit/oraocciXX.so
run path-to-python/python.exe -c "import cx_Oracle" to test whether your setup is working or not.
if it prints
nothing: then it's successful.
ImportError: DLL load failed: The specified module could not be found: then oraocciXX is not found. Setup the env vars correctly.
ImportError: DLL load failed: %1 is not a valid Win32 application: You have a 32/64 bit mismatch.
Yes, you have to have an Oracle client installed at your side.
From the cx_ORacle README
"Please note that an Oracle client (or server) installation is required in order
to use cx_Oracle. If you do not require the tools that come with a full client
installation, it is recommended to install the Instant Client which is far
easier to install."
EDIT link to Instant Client: http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html
After having been trying to solve this issue for days, I found out that set PATH=%PATH%:<insert Oracle home here> did not do the trick for me. I had to go into my Windows XP system properties and append the Oracle home to the 'path' variable under 'System variables'.
I cannot comment yet :-( but for uniquephase above, you may want to try to check the permissions of the .exe and .dlls to make sure they are executable?
So the steps I needed to do to get it working.
Unzip the instant client from here.
http://www.oracle.com/technetwork/topics/winx64soft-089540.html
chmod +x *.exe *.dll (I am using cygwin).
For completeness, I couldnt get cx_oracle to install via pip using cygwin.
So I had to use standard dist python (non-cygwin) and installed cx_oracle via the windows installer.
Also, I had to add f:/opt/instantclient_12_1 (location where I installed the Oracle instant client) to the Windows path (via System->Advanced System Properties->Environment Variables->System Variables).

Error when importing cx_Oracle module [Python]

I use Windows 7 64 bit and Oracle 10g. I have installed python-2.7.2.amd64 and cx_Oracle-5.1-10g.win-amd64-py2.7.
When I importing cx_Oracle module I get this error:
Traceback (most recent call last):
File "C:\Osebno\test.py", line 1, in
import cx_oracle
ImportError: No module named cx_oracle
Can someone please tell me what is wrong?
Have you tried import cx_Oracle (upper-case O) instead of import cx_oracle?
I had this same issue under Windows.
I used Dependency Walker to open up the cx_Oracle.pyd file in C:\Python\Libs\site-libraries\ and reviewed the findings that dependency walker gave.
Dependency Walker showed me that in this case I had the x86 version of Python 2.7.2 installed and x64 version of the Oracle client & client DLL (oci.dll) and was trying to use the x64 version of the cx_Oracle module. With that knowledge I installed Python 2.7.2 x86_64 for Windows and everything was right as rain.
The alternative was to install the x86 version of the Oracle client & cx_Oracle which is much more of a PITA than installing a new Python interpreter.
Also, as this was news to me, you must have the Oracle client installed as well as it provides the 'OCI.dll' client library that cx_Oracle uses. It's located here: Oracle Client Installer Windows x64. Probably helps if one reads the documentation. ;)
Either way, Dependency walker could give you a big clue as to what your issue is if you're having import errors. Unfortunately on-import error messages can be quite ambiguous. I received the same error you referenced and number of other less than specific errors as well.
after installing the cx_Oracle download the instant client form oracle owth all DLLs , then copy then in the same directory of cx_Oracle.pyd , it will work directly
tried and worked for me.
It's not finding the module.
Things to investigate: Do you have several python installations? Did it go to the right one? Do a global search for cx_oracle and see if it's in the correct place. Check your PYTHONPATH variable. Check Python's registry values HKLM\Software\Python\Pyhoncore. Are they correct?
See this answer: https://stackoverflow.com/a/19552263/496289
ignore this.... making up other 17 bytes that're needed to make this post long enough...

Categories

Resources