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 64-bit Oracle Client library: "The specified module could not be found". See https://oracle.github.io/odpi/doc/installation.html#windows for help
cx_Oracle requires Oracle Client libraries. The libraries provide the necessary network connectivity to access an Oracle Database instance.
The easiest solution is as follows:
That is it!
The short answer is: cx_Oracle.init_oracle_client(lib_dir= r"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= r"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 code 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= r"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"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With