cx_Oracle pip install fails: oci.h: No such file or directory

I ran into a similar error trying to pip install cx_oracle, even after installing Oracle instant client, and after setting $ORACLE_HOME and $LD_LIBRARY_PATH to include the path to the client.

It sounds as if you might have installed the Instant Client, but not the Instant Client SDK. The SDK is a separate download/install, and cx_oracle appears to need both, as the missing includes ('oci.h' and all the rest) are located in the SDK.

If you haven't already been there, you can find the Oracle Instant Client / SDK download pages here:

http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html

Assuming that you already downloaded and installed the client appropriate to your platform, e.g. this one:

oracle-instantclient11.2-basic-11.2.0.1.0-1.x86_64.zip

you'll also need to download and install the corresponding SDK, e.g. this one:

oracle-instantclient11.2-sdk-11.2.0.1.0-1.x86_64.zip

As long as the SDK is installed somewhere on the paths in ORACLE_HOME and LD_LIBRARY_PATH, the includes should resolve.


The problem is with SDK not present as pointed out by bschulz. I was able to fix the issue by following these steps:

  1. Downloaded and installed/unzipped the "instantclient-basic" and "instantclient-sdk" in $ORACLE_HOME.

    You can get them from here

  2. Setup the /etc/environment

    export ORACLE_HOME=/opt/oracle/instantclient_12_2
    export LD_LIBRARY_PATH=/opt/oracle/instantclient_12_2
    cd $ORACLE_HOME
    unzip /sdk/ottclasses.zip
    cp -R ./sdk/* .
    cp -R ./sdk/include/* .
    ln -s libclntsh.so.12.1 libclntsh.so
    ln -s libocci.so.12.1 libocci.so
    

Now run pip install cx_Oracle==5.3

I followed these and it successfully installed 5.3 for me.

You may need to install some additional dependencies as listed down in the Documentation of the packages you are supposed to download/installed.

Tags:

Python

Pip