install cx_oracle for python


Am on Debian 5, I've been trying to install cx_oracle module for python without any success. First, I installed oracle-xe-client and its dependency (followed tutorial in the following link here).

Then, I used the scripts in /usr/lib/oracle/xe/app/oracle/product/10.2.0/client/bin to populate environment variables such as PATH, ORACLE_HOME and NLS_LANG.

Once, this was completed, I tried to run:

sudo easy_install cx_oracle

But I keep getting the following error:

Searching for cx-oracle
Best match: cx-Oracle 5.0.4
Processing cx_Oracle-5.0.4.tar.gz
Running cx_Oracle-5.0.4/ -q bdist_egg --dist-dir /tmp/easy_install-xsylvG/cx_Oracle-5.0.4/egg-dist-tmp-8KoqIx
error: cannot locate an Oracle software installation

Any idea what I missed here?

6/19/2014 9:08:57 AM

Accepted Answer

I recommend that you grab the rpm files and install them with alien. That way, you can later on run apt-get purge no-longer-needed.

In my case, the only env variable I needed is LD_LIBRARY_PATH, so I did:

echo export LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client/lib >> ~/.bashrc
source ~/.bashrc

I suppose in your case that path variable will be /usr/lib/oracle/xe/app/oracle/product/10.2.0/client/lib.

4/8/2012 11:39:49 PM

The alternate way, that doesn't require RPMs. You need to be root.

  1. Dependencies

    Install the following packages:

    apt-get install python-dev build-essential libaio1
  2. Download Instant Client for Linux x86-64

    Download the following files from Oracle's download site:

    files preview

  3. Extract the zip files

    Unzip the downloaded zip files to some directory, I'm using:

  4. Add environment variables

    Create a file in /etc/profile.d/ that includes

    export ORACLE_HOME=/opt/ora/instantclient_11_2

    Create a file in /etc/ that includes


    Execute the following command

    sudo ldconfig

    Note: you may need to reboot to apply settings

  5. Create a symlink

    cd $ORACLE_HOME 
    ln -s
  6. Install cx_Oracle python package

    • You may install using pip

      pip install cx_Oracle
    • Or install manually

      Download the cx_Oracle source zip that corresponds with your Python and Oracle version. Then expand the archive, and run from the extracted directory:

      python build 
      python install

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow