简体   繁体   中英

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:\xampp\htdocs\pyoracle\testConnectionOracle.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()

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:\oracle\instantclient_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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM