'Unable to setup connection to Oracle DB using Python cx_Oracle
I am using M1 Mac to connect to Oracle DB using cx_Oracle in Python 3.
import cx_Oracle
import os
import platform
dsn_tns = cx_Oracle.makedsn('host', 'port', service_name='tns_service_name')
conn = cx_Oracle.connect(user='user', password='pwd', dsn=dsn_tns)
cx_Oracle.init_oracle_client(lib_dir='/Users/user/Downloads/instantclient_19_8')
I have followed the instructions from here and installed the oracle client but still unable to connect and gives me the following error.
DatabaseError: DPI-1047: Cannot locate a 64-bit Oracle Client library: "dlopen(libclntsh.dylib, 0x0001): tried: 'libclntsh.dylib' (no such file), '/usr/lib/libclntsh.dylib' (no such file), '/Users/balikuma/Desktop/libclntsh.dylib' (no such file)". See https://cx-oracle.readthedocs.io/en/latest/user_guide/installation.html for help
Solution 1:[1]
To avoid getting the error DPI-1047 in Python on Apple M1 chips, you can upgrade cx_Oracle. The latest major version (which supersedes cx_Oracle 8.3) has a new name python-oracledb. By default this new version doesn't need Oracle Client libraries. Check the installation documentation.
There are also Universal binary packages for macOS x86 and M1 so you don't need to compile the driver or use Rosetta. Packages exist for Python 3.8, 3.9 and 3.10 on macOS.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Christopher Jones |
