dmvianna
dmvianna

Reputation: 15718

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

I'm a bit lost on this one. I also tried to install an older version of cx_Oracle, which I have installed in a separate virtualenv, but it also fails at the same place with the same error message.

$ pip install cx_Oracle
(...)

cx_Oracle.c:10:17: error: oci.h: No such file or directory
cx_Oracle.c:11:18: error: orid.h: No such file or directory
cx_Oracle.c:12:16: error: xa.h: No such file or directory

error: command 'gcc' failed with exit status 1
(...)
----------------------------------------
Cleaning up...
Command /R/.virtualenv/myenv/bin/python -c "import setuptools, tokenize;__file__='/R/.virtualenv/myenv/build/cx-Oracle/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-g5eyNG-record/install-record.txt --single-version-externally-managed --compile --install-headers /R/.virtualenv/myenv/include/site/python2.7 failed with error code 1 in /R/.virtualenv/myenv/build/cx-Oracle
Traceback (most recent call last):
  File "/R/.virtualenv/myenv/bin/pip", line 11, in <module>
    sys.exit(main())
  File "/R/.virtualenv/myenv/lib/python2.7/site-packages/pip/__init__.py", line 185, in main
    return command.main(cmd_args)
  File "/R/.virtualenv/myenv/lib/python2.7/site-packages/pip/basecommand.py", line 161, in main
    text = '\n'.join(complete_log)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 70: ordinal not in range(128)

full error log

Upvotes: 6

Views: 14392

Answers (5)

juggernaut
juggernaut

Reputation: 988

Had experienced the same thing on Mac OS.

First, I've followed this answer and installed instantclient-basic and instantclient-sqlplus via brew.

Then following the same idea I've also downloaded SDK Package (instantclient-sdk-macos.x64-19.3.0.0.0dbru.zip) and executed:

brew install instantclient-sdk

Upvotes: 2

Christopher Jones
Christopher Jones

Reputation: 10586

From cx_Oracle 6:

  • binary wheels are available on PyPI, so many people don't need to compile
  • if you do need to compile, the Oracle header files are not needed, and you shouldn't/needn't set ORACLE_HOME when using Oracle Instant Client.

In cx_Oracle 5.2 and 5.3, if you use the Instant Client RPMs, you do not need to set ORACLE_HOME at install time, and you don't need to set LD_LIBRARY_PATH at runtime. If you use Instant Client zips, (or a real DB $ORACLE_HOME install), you can set FORCE_RPATH=1 before installing cx_Oracle. If you do this, you won't need to set LD_LIBRARY_PATH at runtime. This feature has been in cx_Oracle for a few versions.

Upvotes: 0

Prasannjit Kumar
Prasannjit Kumar

Reputation: 61

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.

Upvotes: 6

kothvandir
kothvandir

Reputation: 2161

As bschulz explains, this problem is usually solved setting ORACLE_HOME and LD_LIBRARY_PATH environment variables to make sure gcc can access to header files. In my case it didn't solve the problem, but inspecting the error trace gave me the hint to solve the problem.

Executing pip install cx_Oracle showed this error:

gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/home/oracle/product/12.1.0/rdbms/demo -I/home/oracle/product/12.1.0/rdbms/public -I/usr/include/python2.7 -c cx_Oracle.c -o build/temp.linux-x86_64-2.7-12c/cx_Oracle.o -DBUILD_VERSION=5.2.1
cx_Oracle.c:10:17: error: oci.h: No such file or directory
cx_Oracle.c:11:18: error: orid.h: No such file or directory
cx_Oracle.c:27:2: error: #error Unsupported version of OCI.

Looking up the -I flag in man gcc:

-I dir  Add the directory dir to the list of directories to be searched for header files.  ....

So the problem was in these flag values:

-I/home/oracle/product/12.1.0/rdbms/demo 
-I/home/oracle/product/12.1.0/rdbms/public 
-I/usr/include/python2.7

I can't really tell why the -I flag was set to those values, but the easy way to make it work was to modify the flag passing the right values from pip command line:

 pip install cx_Oracle --global-option=build_ext --global-option="-I/home/oracle/instantclient_12_1/sdk/include"

This way a new -I value is sent to gcc and the installation ends correctly.

Upvotes: 0

bschulz
bschulz

Reputation: 186

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.

Upvotes: 17

Related Questions