Python module "cx_Oracle" module could not be found
Asked Answered
C

4

11

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.

Carlist answered 21/9, 2012 at 21:13 Comment(0)
V
8

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

Varuna answered 21/9, 2012 at 21:19 Comment(4)
Thanks for the reply, which is really helpful. Another question stands out after that as I moved my script into another environment where an X64 version Oracle is installed, the script failed. I did some research and found that might be due to the fact that the oracle client is 64bit and the python version is 32bit.Carlist
The aforementioned issue solved, by having a "dummy" 32bit Oracle client, and set up the environment variable "ORACLE_HOME" properly to the dummy client path.Carlist
Yes, the oracle client and the Python must match in bits for them to work together.Roxannaroxanne
also helpful #20160066Figurate
A
12
# - 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:
  • 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.
Accipiter answered 23/10, 2013 at 21:5 Comment(1)
To check whether a binary file (dll or exe) is 32-bit or 64-bit, you could also use sigcheck by SysInternals. More info at http://superuser.com/a/808127/283407Spy
V
8

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

Varuna answered 21/9, 2012 at 21:19 Comment(4)
Thanks for the reply, which is really helpful. Another question stands out after that as I moved my script into another environment where an X64 version Oracle is installed, the script failed. I did some research and found that might be due to the fact that the oracle client is 64bit and the python version is 32bit.Carlist
The aforementioned issue solved, by having a "dummy" 32bit Oracle client, and set up the environment variable "ORACLE_HOME" properly to the dummy client path.Carlist
Yes, the oracle client and the Python must match in bits for them to work together.Roxannaroxanne
also helpful #20160066Figurate
L
2

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'.

Lettered answered 25/10, 2013 at 10:4 Comment(0)
C
0

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).

Cytosine answered 11/8, 2016 at 4:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.