cx_Oracle: ImportError: DLL load failed: This appl

2019-01-14 17:01发布

问题:

Here's what I did:

  1. I'm on Windows XP SP3
  2. I already had Python 2.7.1 installed.
  3. I downloaded instantclient-basic-nt-11.2.0.3.0.zip, unzipped it, and put it in C:\Program Files\Oracle\instantclient_11_2.
  4. I added this path to the Windows Path environment variable.
  5. I created a new environment variable ORACLE_HOME holding this path as its value.
  6. 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.

回答1:

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.


回答2:

To help other people with the same problem:

This error tells about 32-64 bit mismatch between some DLL while importing module. Possibilities are:

  1. Different architecture of Python and cx_Oracle (less probable since cx_Oracle installer on Windows warns you if appropriate Python was not found).
  2. 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 founds oci.dll of wrong version of 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 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').



回答3:

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



回答4:

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


回答5:

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>



回答6:

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.



回答7:

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.



回答8:

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



回答9:

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


回答10:

Steps I have followed :

  1. Downloaded the smart client instantclient-basic-windows.x64-12.1.0.2.0.zip

  2. Extracted and copied to #your directory#\instantclient_12_1

    Above directory contains dll's

  3. Append the PATH variable with #your directory#\instantclient_12_1 and created env variable ORACLE_HOME= #your directory#\instantclient_12_1

  4. Download and install cx_Oracle-5.2.1-11g.win-amd64-py2.7.exe

  5. Open idle type import cx_Oracle



回答11:

if you're using Anaconda on Windows try:

conda install cx_oracle

on your cmd

-> this



回答12:

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