How to compile cx_Oracle module on Windows x86

Usually I would not touch with a stick open source package that need to be compiled on Windows. cx_Oracle is different. For me it’s a mandatory python extension module that just need to be there when I need to access Oracle database from python script. Until recently, I was happy with more or less promptly released binaries. They always installed and worked flawlessly. The problem is that at the time of this writing I’m starting to evaluate python 3.1.1 for which cx_Oracle is not yet available. It’s a trivial task to compile cx_Oracle on Linux, but I need Windows version as well. So, for the first time I tried to compile cx_Oracle on Windows by myself.

According to author build instructions, he recommends MinGW compiler for builds on Windows. To make my story short, I downloaded MinGW and to the best of my knowledge tried to compile cx_Oracle module. I miserably failed, each time with an error stating that vcvarsall.bat could not be found. Obviously setup.py script or perhaps python distutils module itself simply expects Microsoft compiler, Visual C++ to be present. After spending a couple of hours searching the web for hints I decided to try another route, with Microsoft Visual Studio Express 2008. Surprisingly cx_Oracle 5.0.2 compiled easily.

Here are the steps that I followed:

  • downloaded cx_Oracle source code (see link “Source code only”) and unpacked the tar in temporary directory
  • downloaded and installed Microsoft Visual C++ 2008 Express edition.
  • downloaded and installed Python 3.1.1
  • downloaded and installed Oracle10g client (10.2.0.4)
  • compiled and installed cx_Oracle:
  • 1) Open Visual Sudio Command Promt, Start -> Run:

    %comspec% /k ""C:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat"" x86

    2) within VS 2008 command prompt cd to directory where you untared cx_Oracle

    C:\Program Files\Microsoft Visual Studio 9.0\VC> cd c:\Python3\cx_Oracle-5.0.2
    C:\Python3\cx_Oracle-5.0.2>

    3) set environment, for example:

    C:\Python3\cx_Oracle-5.0.2> SET ORACLE_HOME=D:\ORACLE\ORA10
    C:\Python3\cx_Oracle-5.0.2> SET PATH=C:\PYTHON3;%ORACLE_HOME%\BIN;%PATH%

    4) compile and install cx_Oracle

    C:\Python3\cx_Oracle-5.0.2> python setup.py build
    C:\Python3\cx_Oracle-5.0.2> python setup.py install

    5) test cx_Oracle by trying to import module

    C:\Python3>python
    Python 3.1.1 (r311:74483, Aug 17 2009, 17:02:12) [MSC v.1500 32 bit (Intel)] on
    win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import cx_Oracle
    >>>

Visual Studio 2008 Express is free but need to be registered within 30 days, registration is completely up to you, if your only goal was to compile cx_Oracle you don’t need registration.

Advertisement

Posted on 30.11.2009, in Scripting and tagged , , . Bookmark the permalink. 1 Comment.

  1. How to compile cx_Oracle for Windows x64
    Recently I posted similar how-to for cx_Oracle 5.0.4 for python 3.2 on Windows x64.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s