Search code examples
oracleoracle11gpython-3.6cx-oracle

Python cx_Oracle error "DPI-1047: Cannot locate a 32-bit Oracle Client"


How fix this error, I use python3.6 and I use Oracle database 11g, I want to connect my python to oracle database, but shows error, how can I fix it?

This is my code:

#importing module
import cx_Oracle

#create a table in oracle database
try:
    con = cx_Oracle.connect('db_employees/root@localhost')

    #Now execute the sqlquery
    cursor = con.cursor()
    cursor.execute("insert into employees values(2171114103970002, raden, ceo, 01031997, batam, 001)")

    #commit that insert the provided database
    con.commit()
except cx_Oracle.DatabaseError as e:
    print("There is a problem with Oracle", e)

#by writing finally if any error occurs
#then also we can close the all database operation
finally:
    if cursor:
        cursor.close()
    if con:
        con.close()

This is messages error:

C:\Python36>python "D:\testing.py"
There is a problem with Oracle DPI-1047: Cannot locate a 32-bit Oracle Client library: "The specified module could not be found". See https://oracle.github.io/odpi/doc/installation.html#windows for help
Traceback (most recent call last):
  File "D:\testing.py", line 20, in <module>
    if cursor:
NameError: name 'cursor' is not defined

Solution

  • Here are the installation instructions: Installing cx_Oracle on Windows.

    The error is saying you need a 32-bit Oracle client library. You can get one from 32-bit Windows Instant Client (The 64-bit libraries are here if anyone needs them) Any version up to 19c will connect to Oracle DB 11.2. Instructions are at the foot of the page. Make sure you have the correct VS redistributable installed.