Skip to content
Advertisement

cx_Oracle connection fails with ‘DPI-1047: Cannot locate a 64-bit Oracle Client library’

Problem use connection oracle to python source, oracle now is worked to other language php (oci)

Error:

Traceback (most recent call last):
  File "c:xampphtdocspyoracletestConnectionOracle.py", line 4, in <module>
    conn = cx_Oracle.connect('xxx','xxx', dsn_tns,'UTF-8')
cx_Oracle.DatabaseError: DPI-1047: Cannot locate a 64-bit Oracle Client library: "failed to get message for Windows Error 126". See https://cx-oracle.readthedocs.io/en/latest/user_guide/installation.html for help

Code:

import cx_Oracle

dsn_tns = cx_Oracle.makedsn('192.168.1.217', '1521', service_name='xx') 
conn = cx_Oracle.connect('xx','xx', dsn_tns,'UTF-8')

c = conn.cursor()
c.execute('select * from database.table')
for row in c:
    print (row[0], '-', row[1])
conn.close()

Advertisement

Answer

Update: try the latest version of cx_Oracle see the release announcement. This version (which was renamed python-oracledb) doesn’t need Instant Client so the installation is easier.

Here are the cx_Oracle Windows installation instructions, which you probably found from the error message you quoted.

I will assume (i) you actually have 64-bit Oracle client libraries 11g or later, and also (ii) have the required VS Redistributable as mentioned in the install instructions. Then a simple thing to try is to add this to the top of your script:

cx_Oracle.init_oracle_client(lib_dir=r"C:oracleinstantclient_19_6")

Use the actual path to your client libraries.

PHP may be 32-bit and using 32-bit Oracle libraries. If so, because you have a 64-bit Python, then you will need to install 64-bit Instant Client or install 32-bit Python. (Note PHP OCI8 doesn’t have an equivalent call to init_oracle_client(). In PHP you need to make sure the Oracle Client libraries are in the system search path e.g. PATH before the PHP process starts.)

Advertisement