Shubham Namdeo
Shubham Namdeo

Reputation: 1925

CX_Oracle import Error for libclntsh.so.12.1

I have Oracle 11g configured in my Ubuntu 16.04 and its working perfectly fine.

Previously I tried to install Oracle 12c, which was giving some errors so I removed it and install 11g.

Now, my problem is that when I try to use import cx_Oracle in python, it gives import error for libclntsh.so.12.1.

Here is the whole output:

>>> import cx_Oracle
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: libclntsh.so.12.1: cannot open shared object file: No such file or directory

My .bashrc file has these entries:

export PATH="/home/marvin/anaconda2/bin:$PATH"
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/xe
export ORACLE_SID=XE
export NLS_LANG=`$ORACLE_HOME/bin/nls_lang.sh`
export ORACLE_BASE=/u01/app/oracle
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
export PATH=$ORACLE_HOME/bin:$PATH

Why is it still trying to take Oracle 12c? Is there is some error in 11g configuration or in 12c uninstall?

I have already tried uninstalling and reinstalling cx_oracle via pip.

Upvotes: 1

Views: 8963

Answers (2)

Lav Patel
Lav Patel

Reputation: 1047

Steps to debug:

1. find file to do ldd on

>>> import imp
>>> imp.find_module("cx_Oracle")
(<_io.BufferedReader name='/opt/data-tools/Anaconda/lib/python3.6/site-packages/cx_Oracle.cpython-36m-x86_64-linux-gnu.so'>, '/opt/data-tools/Anaconda/lib/python3.6/site-packages/cx_Oracle.cpython-36m-x86_64-linux-gnu.so', ('.cpython-36m-x86_64-linux-gnu.so', 'rb', 3))

2. do ldd

    ldd /opt/data-tools/Anaconda/lib/python3.6/site-packages/cx_Oracle.cpython-36m-x86_64-linux-gnu.so

      libclntsh.so.12.1 => not found
  1. find where is libclntsh.so.12.1(or whatever is missing for your case).

  2. make sure dir which contains libclntsh.so.12.1 is in LD_LIBRARY_PATH. If it is not in the path, add it.

     export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/oracle/product/12.1.0/lib/
    

5. Uninstall and install

    /opt/data-tools/Anaconda/bin/pip uninstall cx_Oracle==5.1.3
    export ORACLE_HOME=/opt/oracle/product/12.1.0 &&  /opt/data-tools/Anaconda/bin/pip install cx_Oracle==5.1.3 --no-cache-dir

6. check ldd

    ldd /opt/data-tools/Anaconda/lib/python3.6/site-packages/cx_Oracle.cpython-36m-x86_64-linux-gnu.so
      linux-vdso.so.1 =>  (0x00007ffd89ca2000)
      libclntsh.so.12.1 => /opt/oracle/product/12.1.0/lib/libclntsh.so.12.1 (0x00007f1a3a4ba000)

Upvotes: 1

Anthony Tuininga
Anthony Tuininga

Reputation: 7096

Run the ldd command on the cx_Oracle shared library file that it is trying to load. You should be able to use the "imp" module to find the location of the cx_Oracle module that is being loaded, as in the following:

import imp
imp.find_module("cx_Oracle")

You may discover that the module it is trying to load is found somewhere you didn't expect!

Also, when you run the command to pip install cx_Oracle confirm that it is actually compiling and what files are being linked.

I hope one of those tips are able to help you figure out what the problem is with your configuration.

Upvotes: 5

Related Questions