install cx_oracle for python install cx_oracle for python python python

install cx_oracle for python


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:

    /opt/ora/
  4. Add environment variables

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

    export ORACLE_HOME=/opt/ora/instantclient_11_2export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME

    Create a file in /etc/ld.so.conf.d/oracle.conf that includes

    /opt/ora/instantclient_11_2

    Execute the following command

    sudo ldconfig

    Note: you may need to reboot to apply settings

  5. Create a symlink

    cd $ORACLE_HOME ln -s libclntsh.so.11.1 libclntsh.so
  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 setup.py build python setup.py install


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 >> ~/.bashrcsource ~/.bashrc

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


The following worked for me, both on mac and Linux. This one command should download needed additional files, without need need to set environment variables.

python -m pip install cx_Oracle --pre

Note, the --pre option is for development and pre-release of the Oracle driver. As of this posting, it was grabbing cx_Oracle-6.0rc1.tar.gz, which was needed. (I'm using python 3.6)