Search code examples
oraclecx-oracledjango-databaseoracle-cloud-infrastructurepython-oracledb

Can not find 64-bit Oracle Client Library when connection to Oracle Cloud Autonomous Database with Django


Following this tutorial, I am getting the below error when I try to python manage.py runserver

django.db.utils.DatabaseError: DPI-1047: Cannot locate a 64-bit Oracle Client library: "dlopen(libclntsh.dylib, 0x0001): tried: 'libclntsh.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OSlibclntsh.dylib' (no such file), '/usr/lib/libclntsh.dylib' (no such file, not in dyld cache), 'libclntsh.dylib' (no such file), '/usr/lib/libclntsh.dylib' (no such file, not in dyld cache)". See https://cx-oracle.readthedocs.io/en/latest/user_guide/installation.html for help

I have installed both cx_oracle and oracledb and nothing has worked. I have Oracle Instant Client for macOS (Intel x86) installed and the wallet is pulled down in the correct location as well.

Are there environment variables I can set to tell with cx_oracle or oracledb where the Oracle libraries are located?


Solution

  • If you see this error with python-oracledb, then your application contains a call to init_oracle_client(). You could remove all such calls and use the default Thin mode.

    If you want to continue with python-oracledb 'Thick' mode, or you are using the older version of the driver (cx_Oracle), then change your init_oracle_client() calls and pass the lib_dir parameter. (This works on macOS Intel and Windows). See Setting the Oracle Client Library Directory on macOS. For example:

    import oracledb
    
    oracledb.init_oracle_client(lib_dir="/Users/your_username/Downloads/instantclient_19_8")
    

    To connect to Oracle ADB, be aware that the syntax differs between python-oracledb Thin & Thick modes. See Connecting to Oracle Cloud Autonomous Databases.