Skip to content

Instantly share code, notes, and snippets.

@floer32
Last active January 6, 2020 23:29
Show Gist options
  • Star 31 You must be signed in to star a gist
  • Fork 12 You must be signed in to fork a gist
  • Save floer32/5547377 to your computer and use it in GitHub Desktop.
Save floer32/5547377 to your computer and use it in GitHub Desktop.
CentOS 6: Set up Oracle Instant Client and Python package cx_Oracle
#!/bin/bash
# INSTALL ORACLE INSTANT CLIENT #
#################################
# NOTE: Oracle requires at least 1176 MB of swap (or something around there).
# If you are using CentOS in a VMWare VM, there's a good chance that you don't have enough by default.
# If this describes you and you need to add more swap, see the
# "Adding a Swap File to a CentOS System" section, here:
# http://www.techotopia.com/index.php/Adding_and_Managing_CentOS_Swap_Space
# Install basic dependencies
sudo yum -y install libaio bc flex
echo "Now go get some the following two RPMs ..."
echo "- basic: oracle-instantclient11.2-basic-11.2.0.3.0-1.x86_64.rpm"
echo "- SDK/devel: oracle-instantclient11.2-devel-11.2.0.3.0-1.x86_64.rpm"
echo "... from this URL: http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html"
echo "WARNING: It's pretty annoying, they make you sign up for an Oracle account, etc."
echo 'I will assume you have put these two files are into ~/Downloads'
echo "Press any key once you're ready" && read -n 1 -s
sudo rpm -ivh ~/Downloads/oracle-instantclient11.2-basic-*
sudo rpm -ivh ~/Downloads/oracle-instantclient11.2-devel-*
# SET ENVIRONMENT VARIABLES #
#############################
# Source for this section: http://cx-oracle.sourceforge.net/BUILD.txt
# (SIDENOTE: I had to alter it by doing some digging around for where the Oracle RPMs really installed to;
# if you ever need to do this, do a command like this:
# rpm -qlp <rpm_file_of_concern.rpm>)
echo '# Convoluted undocumented Oracle bullshit.' >> $HOME/.bashrc
echo 'export ORACLE_VERSION="11.2"' >> $HOME/.bashrc
echo 'export ORACLE_HOME="/usr/lib/oracle/$ORACLE_VERSION/client64/"' >> $HOME/.bashrc
echo 'export PATH=$PATH:"$ORACLE_HOME/bin"' >> $HOME/.bashrc
echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:"$ORACLE_HOME/lib"' >> $HOME/.bashrc
. $HOME/.bashrc
# INSTALL cx_Oracle #
#####################
pip install cx_Oracle
@max-reznichenko
Copy link

Thanks @hangtwenty this gist saved my day

@rofrol
Copy link

rofrol commented Oct 10, 2013

Thank you

@tomrenn
Copy link

tomrenn commented Nov 21, 2013

Note to anyone else, use 11.2, cx_Oracle doesn't seem to know how to check for instantclient version 12.1

@ninetythirty
Copy link

Thanks for this.
Using your notes I was able to build cx_Oracle 5.1.2 for Instant Client 12.1 by making two changes to cx_Oracle's setup.py:

Line 89: check for version 12.1 shared object file

                ("11g", "libclntsh.so.12.1"),

Lines 162-163: search for plain old "include"

    possibleIncludeDirs = ["rdbms/demo", "rdbms/public", "network/public",
            "sdk/include", "include"]

@meetjeremy
Copy link

during build i'm getting error

running build
running build_ext
building 'cx_Oracle' extension
x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/lib/oracle/12.1/client64/lib/ -I/usr/include/python2.7 -c cx_Oracle.c -o build/temp.linux-x86_64-2.7-11g/cx_Oracle.o -DBUILD_VERSION=5.1.2
cx_Oracle.c:10:17: fatal error: oci.h: No such file or directory
#include < oci.h >
^
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

I've installed instantclient-basic 12.1, dlevel and sqlplus

any help?

@autodidacticon
Copy link

@meetjeremy: I ran into the same problem; if you havent already, the zipped version of the oracle 11.2 sdk contains the appropriate files whereas the rpm does not. Get it and unzip, and move the 'sdk' folder into /usr/lib/oracle/11.2/client64/lib/

http://download.oracle.com/otn/linux/instantclient/11204/instantclient-sdk-linux.x64-11.2.0.4.0.zip

@jackward
Copy link

After many frustrating hours of trying to get cx_Oracle loaded, I found this guide and using it I finally got things going.. Although the procedure needed mods for oracle updates, your verbose commenting provided the clues that no one else actually provided.. Thank you and keep up the good documentation

@jacobw125
Copy link

This was really helpful, thank you. I can confirm it works on Oracle v12.1 (with RHEL6) as well. For the record (and to help future searchers), the error I was getting before I followed these instructions was something like:

... "/site/python2.7" failed with error code 1 in /tmp/pip-build-MBbOFN/cx-Oracle

@edwardrf
Copy link

If you are facing the problem of unable to find oci.h like i do, you need to install the SDK for instant client packge, apparently in the new version the headers has been separated into a different download.

Instant Client Package - SDK: Additional header files and an example makefile for developing Oracle applications with Instant Client

@guptarohit123
Copy link

This article and the comments were really helpful. @2 hours 21 minutes of frustration could have been avoided if I found this earlier/
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment