Pensieri di un lunatico minore

27 August 2008 Python

Python, Oracle and Windows

If there’s one thing I hate more than Windows, it’s AIX. I admit it. While I know that AIX has some amazing capabilities sorely lacking in other UNIXish operating systems, dealing with software development on an AIX box is just too painful to speak of. So, in order to reduce my pain, I’m developing some integration software (Cisco CallManager with some proprietary back-end systems) on my Windows notebook in the interim.

Here’s the steps to getting Oracle and Python happy on Windows. This assumes you’re using Python v2.5 on Windows XP, or similar:

  1. Download Oracle’s Instant Client from their website. You probably only need two packages: Basic Lite and SQL*Plus.
  2. Unpack the downloaded Instant Client into C:\instantclient.
  1. Open a command line and CD C:\instantclient then run SQL*Plus with a command like sqlplus test/test@//192.168.1.100:1521/MYDB. This should connect you to the Oracle database. There’s more information here.

    Assuming all of the above work fine, you’re good to start with making sure things can be found by Python, et. al.

  2. Go to your desktop, and right click on My Computer, select Properties, then the Advanced tab.
  3. Click on the button labeled Environment Variables.
  4. Under System Variables, find the variable Path and click Edit.
  5. Append a semicolon to the displayed list of directories and append C:\instantclient.
  6. Click OK enough times to get out of all the dialogs
  1. Log out and back in of Windows to make sure the path settings “take”

    Now we need to install the Python Oracle adapter. For my purposes, even though I once worked on another Oracle adapter, I recommend cx_Oracle. I’m using version 4.3.1 successfully.

  2. Download the Windows installer for whichever version of Python (2.5) and Oracle (10g) you are using1.
  1. Run the installer, accepting the defaults, or changing as appropriate.

    You should be done at this point. Pop open a Python interpreter and type in the following:

    >>> import cx_Oracle
    >>> ora = cx_Oracle.connect("test/test@//192.168.1.100:1521/MYDB")
    >>> ora
    <cx_oracle .Connection to test/test@//192.168.1.100:1521/MYDB>
    >>> ora.version
    '10.2.0.3.0'
    >>></cx_oracle>

    Assuming everything is installed correctly, and your remote Oracle instance is allowing network connections, you should get back a connection object that you can use to work with Oracle. The rest is your problem.

    1 As far as I know, there’s no pre-built version against the 11g release, but you should be able to do anything you need with the older libraries. I’ve had no problems with the 10g cx_Oracle using the 11g Instant Client.

    This entry was posted at 4:16 pm on 27 August 2008 and is filed under Python. You can follow any responses to this entry through the post-specific RSS 2.0 feed.

    No comments found.

    Both comments and pings are currently closed.