cx_Oracle error. DPI-1047: Cannot locate a 64-bit Oracle Client library

后端 未结 5 1637
灰色年华
灰色年华 2020-12-10 04:43

I installed the library and when trying to access SQL in jupyter notebook with my credentials the following error appears:

DatabaseError: DPI-1047: Cannot locate a 6

相关标签:
5条回答
  • 2020-12-10 05:18

    Probably you have installed cx_Oracle Python library. In order to execute the DB connectivity through jupyter notebook, you need to install the Oracle Client and that is what missing in your scenario. Please follow the steps from below link and and install Oracle Client and this will solve your problem: https://oracle.github.io/odpi/doc/installation.html#windows

    0 讨论(0)
  • 2020-12-10 05:20

    I suggest you to first check the compatibility of your OS, Python and Oracle Instant Client architecture:

    import platform
    platform.architecture()
    

    Then, I definitely advise you to set the Oracle Instant Client inside your jupyter notebook:

    import os
    os.environ["PATH"] = "Complete Location of Instant Client Folder" + ";" + os.environ["PATH"]
    
    0 讨论(0)
  • 2020-12-10 05:30

    The easiest solution is as follows:

    1. Download 64-bit version of oracle instantClient from: https://www.oracle.com/database/technologies/instant-client/winx64-64-downloads.html
    2. Copy the dll files in the instantclient directory to the python directory, as shown below

    That is it!

    0 讨论(0)
  • 2020-12-10 05:35

    Make sure you have installed the correct oracle client (you can find the oracle client package from here "https://www.oracle.com/in/database/technologies/instant-client/winx64-64-downloads.html" and add the downloaded folder inside the folder where python is installed and then add this location (location of your client package folder) to system's environment variable. Hope that will work.

    0 讨论(0)
  • 2020-12-10 05:38

    The short answer is: cx_Oracle.init_oracle_client(lib_dir= "c:\path_to_libraries")

    Here are the steps that I followed to solve this same issue:

    If you have not already installed cx_Oracle you can do so with the following command:
    python -m pip install cx_Oracle --upgrade

    The cx_Oracle documentation can be found here.

    Use the following commands to verify that everything is installed and recognized:

    import sqlalchemy as sqla
    import pandas as pd
    import cx_Oracle
    
    # Test to see if it will print the version of sqlalchemy
    print(sqla.__version__)    # this returns 1.2.15 for me
    
    # Test to see if the cx_Oracle is recognized
    print(cx_Oracle.version)   # this returns 8.0.1 for me
    
    # This fails for me at this point but will succeed after the solution described below
    cx_Oracle.clientversion()  
    

    At this point I get errors saying the libraries cannot be located. Here is the solution:

    import os
    import platform
    
    # This is the path to the ORACLE client files
    lib_dir = r"C:\put_your_path_here\instantclient-basic-windows.x64- 19.9.0.0.0dbru\instantclient_19_9"
    
    # Diagnostic output to verify 64 bit arch and list files
    print("ARCH:", platform.architecture())
    print("FILES AT lib_dir:")
    for name in os.listdir(lib_dir):
        print(name)
    

    Be sure to update the lib_dir path specific to your installation. If you have the correct path, you should see a listing of all the Oracle files like: (adrci.exe, oci.dll, oci.sym, etc). This is the location that Python needs to be able to find the Oracle drivers.

    The current (Nov 2020) standard way for passing the location of the Oracle libraries for Windows is cx_Oracle.init_oracle_client(lib_dir= "c:\path_to_libraries"). Here is an example:

    lib_dir = r"C:\put_your_path_here\instantclient-basic-windows.x64- 19.9.0.0.0dbru\instantclient_19_9"
    
    try:
        cx_Oracle.init_oracle_client(lib_dir=lib_dir)
    except Exception as err:
        print("Error connecting: cx_Oracle.init_oracle_client()")
        print(err);
        sys.exit(1);
    

    At this point I can run the following error without any errors:

    # This works after passing the lib_dir path
    cx_Oracle.clientversion()    # For me it returns: (19, 9, 0, 0, 0)
    

    DEPRECATED Here is how to update the PATH variable temporarily:

    The following works, but using cx_Oracle.init_oracle_client(lib_dir= "c:\path_to_libraries") is now the preferred way.

    import os   
    # Manually append the location of the ORACLE libraries to the PATH variable
    os.environ["PATH"] = lib_dir + ";" + os.environ["PATH"]
    
    0 讨论(0)
提交回复
热议问题