Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python cx_Oracle Client Library Cannot Be Loaded

Tags:

python

oracle

I am trying to connect to an Oracle database but python script cannot find cx_Oracle. Here is my script:

import cx_Oracle
con = cx_Oracle.connect(‘DBNAME/[email protected]:1521/yeppers’)
print(con.version)
con.close()

This is the error I get:

================= RESTART: C:\Python35\Connect_To_Oracle.py =================
Traceback (most recent call last):
  File "C:\Python35\Connect_To_Oracle.py", line 1, in <module>
   import cx_Oracle
cx_Oracle.DatabaseError: DPI-1047: Oracle Client library cannot be loaded: The specified module could not be found. See https://oracle.github.io/odpi/doc/installation.html for help

Here is my O/S and version info:

  • Intel Xeon CPU E7-4870 @ 2.40GHz
  • Windows Server 2008 R2 Enterprise
  • Python 3.5

Here is what I did to install cx_Oracle:

1. Download Instant Client (Basic Client) from Oracle here : http://www.oracle.com/technetwork/topics/winx64soft-089540.html .
2. Unzip.
3. I added a new System Variable called ORACLE_HOME and pointed it to c:\Down\InstantClient , which is where I unzipped the above.  This is what I downloaded: instantclient-basic-windows.x64-12.2.0.1.0
4. You have to download the whl file from here: https://pypi.python.org/pypi/cx_Oracle/  To do this, you need to know your version of Python and your type of processor.  
5. You download into the scripts folder and then run pip install wheelfilename.whl

Can someone please let me know what they think that error stems from?

like image 754
user8340926 Avatar asked Jul 20 '17 22:07

user8340926


People also ask

Does cx_Oracle require Oracle client?

cx_Oracle requires Oracle Client libraries. The libraries provide the necessary network connectivity to access an Oracle Database instance.

What is Python cx_Oracle?

cx_Oracle is a Python extension module that enables access to Oracle Database. It conforms to the Python database API 2.0 specification with a considerable number of additions and a couple of exclusions.

How do you find the DPI of a 1047?

To Solve DatabaseError: DPI-1047: Cannot locate a 64-bit Oracle Client library: “The specified module could not be found” First of all install install cx_Oracle using this command. python -m pip install cx_Oracle –upgrade Now Just download Oracle Basic Client and Extract It.


2 Answers

The instructions URL in the DPI-1047 error show to set PATH to the location of the Instant Client libraries. Also you need the correct VS Redistributable - all given in the instructions. Note they don't mention setting ORACLE_HOME.

Make sure Instant Client is the same 32-bit or 64-bit architecture as Python is.

The cx_Oracle installation instructions are at https://cx-oracle.readthedocs.io/en/latest/user_guide/installation.html

With cx_Oracle 8 on Windows (and macOS, but not Linux), you can make use of init_oracle_client() to say where the Instant Client libraries are. This is instead of setting PATH.

like image 118
Christopher Jones Avatar answered Oct 08 '22 17:10

Christopher Jones


When I was setting up my python environment I added the instantclient files within my PATH variable for a windows box, I don't even have anything for ORACLE_HOME defined. Adding it to your PATH might help with the process.

But when you installed the whl file there was no errors or messages?

Are you able to install the cx_Oracle module via pip instead? The cx_Oracle websites lists the command as python -m pip install cx_Oracle but I believe you should be able to do it with pip3 install cx_Oracle if you have your PATH variable setup correctly.

Do you see cx_Oracle in your $Python/Lib/site-packages/ directory? If you can't find your site packages use this within your IDLE to find where it is.

>>> import site
>>> site.getsitepackages()
['C:\\Python36', 'C:\\Python36\\lib\\site-packages']
like image 34
stephen Avatar answered Oct 08 '22 16:10

stephen