7

Im using python 2.7 and cx_oracle ( Windows x86 Installer (Oracle 10g, Python 2.7) ) and 'm having a bad time to set this simple example bellow to work:

import cx_Oracle
connection = cx_Oracle.connect('user/pass@someserver:port')
cursor = connection.cursor()
cursor.execute('select sysdate from dual')

for row in cursor:
    print row
connection.close()

Error Message:

Traceback (most recent call last):
  File "C:\ORACON.py", line 1, in <module>
    import cx_Oracle
ImportError: DLL load failed: The specified module could not be found.

For now, what i have done was:

1) installed the cx_oracle binary;

2) downloaded instantclient_10_2 from oracle website and exported the path to environment;

Anyone know what im missing?

Thank you for your time on reading this.

DIDoS
  • 812
  • 9
  • 23
thclpr
  • 5,778
  • 10
  • 54
  • 87
  • The last time I have seen this issue, there was a mismatch in bitness. Try debugging with [procmon](http://technet.microsoft.com/en-in/sysinternals/bb896645.aspx) – Abhijit Dec 04 '12 at 18:01

1 Answers1

22

I was able to solve this problem with the following steps:

  1. Download instantclient-basic-win32-10.2.0.5 from Oracle Website

  2. unzipped the into my c:\ with the name oraclient

  3. Created the directory structure C:\oraclient\network\admin to add the TNSNAMES.ORA

  4. Added the TNS_ADMIN env var pointing to C:\oraclient\network\admin

  5. Added the ORACLE_HOME env var pointing to C:\oraclient\

After that i used the following code:

import cx_Oracle

con = cx_Oracle.connect('theuser', 'thepass', 'your DB alias on your TNSNAMES.ORA file ')
cur = con.cursor()
if cur.execute('select * from dual'):
    print "finally, it works!!!"
else:
    print "facepalm"
con.close()

I hope it helps someone.

thclpr
  • 5,778
  • 10
  • 54
  • 87
  • 13
    use `cx_Oracle.connect('theuser', 'thepass', cx_Oracle.makedsn('host', port, SID))` and you can avoid steps 3, 4 and 5. – Kashyap Oct 23 '13 at 21:24
  • 1
    i guess you still need to have c:\oraclient (cf step 2) in your os.environ['PATH'] variable – comte Dec 29 '14 at 17:25
  • @comte It could be added yes, but works without it too. – thclpr Jan 05 '15 at 17:29
  • SIDs have been deprecated, it's best to use your TNSNAMES.ORC which have Service Name, unlike SIDs which makedsn() creates https://community.oracle.com/thread/3650176 – EoinS Aug 15 '16 at 18:41