3

I have been able to successfully install cx_Oracle for use with Python 3.4 on my Windows 8 laptop, and I am now trying to get the same setup (cx_Oracle with Python 3.4) onto a Linux machine. When running the setup.py file from cx_Oracle-5.1.3.tar.gz, I end up with this error:

    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

Following some other answers I looked at (easy_install cx_Oracle (python package) on Windows, https://gist.github.com/jarshwah/3863378) I have installed these 3 instant client rpms:

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

And then I set ORACLE_HOME to the folder that they were installed to, which is supposed to help python identify the location of the oracle files so it can do the installation properly.

I still get the same "cannot locate an Oracle software installation" error each time I try to run the setup.py file.

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

Update for more info:

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

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 the directory I have for my Windows 8 install - that one has .dll and .sym files, like orasql12.dll. Should the Linux version of the instant client install have different files?

Update with partial solution:

I found a solution that installed cx_Oracle properly, 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

And then I created a Symbolic link:

ln -s libclntsh.so.12.1 libclntsh.so

After that, going to the cx_oracle folder and doing this worked:

python3 setup.py build
python3 setup.py install

For some reason, sudo python3 setup.py install did not work for this.

Update with link to related question:

My next problem is getting the environment variables to persist outside of the shell instance so I don't have to define the environment variables each time. The environment variables I put in profile.d show up when I echo them, but python fails to import cx_oracle properly, and I have to export the environment variables again for some reason. I don't know the proper procedure for posting a different question related to one, so I opened a new question here:

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

Please help me out with this, I feel completely stuck on what to try to make it work. The environment variables show up when I echo them, but they only seem to be functional if I export them again before running the python code.

Community
  • 1
  • 1
Acuity
  • 43
  • 1
  • 6
  • Did you export the `ORACLE_HOME` shell variable? `export ORACLE_HOME=/your/oracle/dir` – mhawke Jun 19 '15 at 01:27
  • Yep, I did. And `echo $ORACLE_HOME` returns my oracle directory `/instantclient_12_1` Is that correct? – Acuity Jun 19 '15 at 06:17
  • If you have the downloaded the RPMs from [Instant Client Downloads for Linux x86](http://www.oracle.com/technetwork/topics/linuxsoft-082809.html) and installed using `rpm -ivh` , the files should be installed in `/usr/lib/oracle`, not `/instantclient_12_1`. Are you sure that you installed with `rpm` or did you install by extracting the zip files available from the same download page? – mhawke Jun 19 '15 at 08:55
  • I see, I found the `/usr/lib/oracle` folder. Do I set `ORACLE_HOME` to be `/usr/lib/oracle`? I'll try that and see if it works. I'm not very sure where the `/instantclient_12_1` folder came from. – Acuity Jun 19 '15 at 15:33
  • I am trying `/usr/lib/oracle` as `ORACLE_HOME` and I have also added `ORACLE_HOME` to `PATH`, still get the same error message when running setup.py. Any other ideas? `echo $ORACLE_HOME` gives me `/usr/lib/oracle` and `echo $PATH` gives me `/usr/lib/oracle:/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/maven/apache-maven-3.2.5/bin:/root/bin`, I put the oracle home folder first. – Acuity Jun 19 '15 at 17:41

2 Answers2

4

Updated

As Petriborg suggested, setting LD_RUN_PATH at build time will include the path to the Oracle shared library files in the cx_Oracle shared library that is built during installation. This obviates the need for LD_LIBRARY_PATH as I suggested in my first answer.


For the RPMs that 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 info on installing and executing applications that use the client libraries.

Community
  • 1
  • 1
mhawke
  • 84,695
  • 9
  • 117
  • 138
  • 1
    Instead of setting LD_LIBRARY_PATH, if you set LD_RUN_PATH during build time, the library path will be added to the .so files, and they will auto magically locate the library. See http://stackoverflow.com/a/882150/2815 – Petriborg Jun 20 '15 at 00:43
  • @Petriborg: thanks for that, I didn't know about `LD_RUN_PATH` but it is definitely better than specifying `LD_LIBRARY_PATH`. I've updated the answer with that info. Thanks – mhawke Jun 20 '15 at 11:23
  • Thanks for the answers. I am not using `pip`, I am just using the straight up `setup.py` file from the `cx_oracle` folder. Either way, I found something that got cx_oracle installed for me, and updated it in my question! – Acuity Jun 22 '15 at 15:40
  • Another thing I ran into: when using the `/usr/lib/oracle/12.1/client` path for `ORACLE_HOME` and for `LD_LIBRARY_PATH`, I run into this error when I try to run code that uses cx_oracle: `ImportError: libclntsh.so.12.1: wrong ELF class: ELFCLASS32`. I don't know why, but my `instantclient_12_1` directory works instead. Am I supposed to reinstall cx_oracle using the `LD_RUN_PATH` environment variable? – Acuity Jun 23 '15 at 17:22
0

When I tried installing cx_Oracle with LD_LIBRARY_PATH variable alone in Ubuntu 16.04 with python 2.7.12 and Oracle client 12.1.0.2 pip install fails and is looking for header files which are no more available with Oracle 12.1.0.2 client. It works fine with LD_RUN_PATH

  • During cx_Oracle 5.2 installation you can set FORCE_RPATH=1 so that cx_Oracle uses rpath. With this, you shouldn't need LD_LIBRARY_PATH or LD_RUN_PATH. – Christopher Jones Dec 19 '16 at 04:13