Python – cx_Oracle does not recognize the Oracle software installation location used for installation on Linux

cx_Oracle does not recognize the Oracle software installation location used for installation on Linux… here is a solution to the problem.

cx_Oracle does not recognize the Oracle software installation location used for installation on Linux

I

have been able to successfully install cx_Oracle for Python 3.4 on my Windows 8 laptop, and now I’m trying to get the same setup on a Linux machine (cx_Oracle and Python 3.4). I got this error when running setup.py files from cx_Oracle-5.1.3.tar.gz:

    sudo python3 setup.py install
    Traceback (most recent call last):
       File "setup.py", line 135, in <module>
          raise DistutilsSetupError("cannot locate an Oracle software " \
    distutils.errors.DistutilsSetupError: cannot locate an Oracle software installation

According to some of the other answers I’ve looked at ( easy_install cx_Oracle (python package) on Windows https://gist.github.com/jarshwah/3863378), I installed these 3 instant client rpm:

rpm -ivh oracle-instantclient12.1-basic-12.1.0.2.0-1.i386.rpm
rpm -ivh oracle-instantclient12.1-devel-12.1.0.2.0-1.i386.rpm
rpm -ivh oracle-instantclient12.1-sqlplus-12.1.0.2.0-1.i386.rpm

Then I set the ORACLE_HOME to the folder they were installed into, which should help python identify the location of the oracle files so that it can install correctly.

Every time I try to run the setup.py file, I still get the same “Oracle software installation not found” error.

Any idea what I need to do to successfully install cx_oracle?

Update for more information:

echo $ORACLE_HOME returns /instantclient_12_1, which is where the rpm file is installed.

This is the contents of my /instantclient_12_1 directory:

adrci                  libnnz12.so       libsqlplusic.so  tnsnames.ora
BASIC_README           libocci.so        libsqlplus.so    tnsnames.ora_andy
genezi                 libocci.so.12.1   ojdbc6.jar       uidrvci
glogin.sql             libociei.so       ojdbc7.jar       xstreams.jar
libclntshcore.so.12.1  libocijdbc12.so   sdk
libclntsh.so           libons.so         sqlplus
libclntsh.so.12.1      liboramysql12.so  SQLPLUS_README

This is a bit different from my Windows 8 installation directory – that directory has .dll and .sym files, like orasql12.dll. Should the Linux version installed by the instant client have different files?

Update some solutions:

I found a solution to install cx_Oracle correctly, but only during that shell instance:

I set these two environment variables:

export ORACLE_HOME=/instantclient_12_1
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME

Then I created a symbolic link:

ln -s libclntsh.so.12.1 libclntsh.so

After that, go to the cx_oracle folder and do this:

python3 setup.py build
python3 setup.py install

For some reason, sudo python3 setup.py install doesn’t work for this.

Update link to related issue:

My next problem is to have environment variables persist outside of the shell instance so that I don’t have to define environment variables every time. The environment variables I put in profile.d show up on my echo, but python doesn’t import cx_oracle correctly, and for some reason I had to export the environment variables again. I don’t know the correct program for posting different issues related to one issue, so I opened a new issue here :

Linux profile.d environment variables don’t work with cx_oracle in Python

Please help me with this, I feel completely unable to try to get it to work. When I echo them, the environment variables show up, but they only seem to work if you export them again before running the python code.

Solution

Updated

as Petriborg suggested at build time to set the path LD_RUN_PATH the cx_Oracle shared repository that will be built during installation to contain the Oracle shared library files. As I suggested in the first answer, this eliminates the need for LD_LIBRARY_PATH.


For the RPM you are using, ORACLE_HOME should be set to /usr/lib/oracle/12.1/client. If you are using pip:

$ export ORACLE_HOME=/usr/lib/oracle/12.1/client
$ export LD_RUN_PATH=/usr/lib/oracle/12.1/client/lib:$LD_RUN_PATH
$ pip install cx_Oracle
$ python -c 'import cx_Oracle; print(cx_Oracle.version)'
5.1.3

Read this documentation for some information about installing and executing applications that use client libraries.

Related Problems and Solutions