Python module “cx_Oracle” module could not be found

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

Leave a Comment