Silas Ray Silas Ray - 4 months ago 59
Python Question

easy_install cx_Oracle (python package) on Windows

So I found Help installing cx_Oracle but am still stuck. I downloaded the latest instantclient from oracle, and set ORACLE_HOME to the location of the extracted files (both direct and with a bin folder between the ORACLE_HOME value and the files), but easy_install is popping an error when running setup.py saying it can't locate the Oracle include files. I did notice that only the 11g dll is in the folder, do I need all 3 drivers present for setup to complete? If so, where do I even get them?

Answer

Honestly it is a hell of a lot easier to install cx_Oracle from one of the binary installers they have, than from source.

HOWTO for *nix:

  1. Browse to Instant Client for Linux x86 download page.

  2. Download the latest version of basic, sqlplus and sdk packages that fit your architecture (32 or 64bits):

    • oracle-instantclient<version>-basic-<version_full>.<arch>.rpm
    • oracle-instantclient<version>-sqlplus-<version_full>.<arch>.rpm
    • oracle-instantclient<version>-devel-<version_full>.<arch>.rpm.
  3. Install the RPMs using alien. For example, at the time of this writing:

    $ sudo alien -i oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpm
    
  4. Add necessary environment variables (I personally did put it in /etc/environment then logoff/back in to reload the env):

    ORACLE_HOME=/usr/lib/oracle/<version>/client64/lib/
    LD_LIBRARY_PATH=/usr/lib/oracle/<version>/client64/lib/
    
  5. Fix oracle's includes:

    $ sudo ln -s /usr/include/oracle/<version>/client $ORACLE_HOME/include  # for 32bits arch, OR
    $ sudo ln -s /usr/include/oracle/<version>/client64 $ORACLE_HOME/include  # for 64bits arch
    
  6. Create /etc/ld.so.conf.d/oracle-instantclient<version>-basic.conf and /etc/ld.so.conf.d/oracle.conf (for more recent versions, at least since 12.1) containing:

      /lib  
      /usr/lib/oracle/<version>/client/lib  ; for 32bits arch, OR
      /usr/lib/oracle/<version>/client64/lib  ; for 64bits arch
    
  7. Reload ldconfig cache (use -v flag if you want some verbose):

    $ sudo ldconfig
    

You might need to install libaio1.

HOWTO Install cx_Oracle

Assuming we have installed Oracle Instant Client 10, you have different alternatives to install cx_Oracle:

  1. Install with pip: $ pip install cx_oracle (linux only)
  2. Download the installer/.tar.gz file from the cx_oracle PyPI site

Older versions (version less than 5.1.2 are .msi and .rpm files) can be downloaded from here. Install the RPMs using alien. For example, at the time of this writing: $ sudo alien -i cx_Oracle-5.0-10g-py25-1.x86.rpm

To test, python -c 'import cx_Oracle; print cx_Oracle' should return the modules with its version.

Comments