Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

install cx_oracle for python

Tags:

python

oracle

Am on Debian 5, I've been trying to install cx_oracle module for python without any success. First, I installed oracle-xe-client and its dependency (followed tutorial in the following link here).

Then, I used the scripts in /usr/lib/oracle/xe/app/oracle/product/10.2.0/client/bin to populate environment variables such as PATH, ORACLE_HOME and NLS_LANG.

Once, this was completed, I tried to run:

sudo easy_install cx_oracle 

But I keep getting the following error:

Searching for cx-oracle Reading http://pypi.python.org/simple/cx_oracle/ Reading http://cx-oracle.sourceforge.net Reading http://starship.python.net/crew/atuining Best match: cx-Oracle 5.0.4 Downloading http://prdownloads.sourceforge.net/cx-oracle/cx_Oracle-5.0.4.tar.gz?download Processing cx_Oracle-5.0.4.tar.gz Running cx_Oracle-5.0.4/setup.py -q bdist_egg --dist-dir /tmp/easy_install-xsylvG/cx_Oracle-5.0.4/egg-dist-tmp-8KoqIx error: cannot locate an Oracle software installation 

Any idea what I missed here?

like image 340
Mo J. Mughrabi Avatar asked Nov 29 '10 19:11

Mo J. Mughrabi


People also ask

What is Python cx_Oracle?

cx_Oracle is a Python extension module that enables access to Oracle Database. It conforms to the Python database API 2.0 specification with a considerable number of additions and a couple of exclusions.

Do you need Oracle client for cx_Oracle?

Using cx_Oracle requires Oracle Client libraries to be installed. These provide the necessary network connectivity allowing cx_Oracle to access an Oracle Database instance. Oracle Client versions 19, 18, 12 and 11.2 are supported.

Can I connect Oracle Database with Python?

Python can connect to oracle using a python package called cx_Oracle. Oracle is one of the famous and widely used database and python's data processing features are leverages well using this connectivity.


1 Answers

The alternate way, that doesn't require RPMs. You need to be root.

  1. Dependencies

    Install the following packages:

    apt-get install python-dev build-essential libaio1 
  2. Download Instant Client for Linux x86-64

    Download the following files from Oracle's download site:

    files preview

  3. Extract the zip files

    Unzip the downloaded zip files to some directory, I'm using:

    /opt/ora/ 
  4. Add environment variables

    Create a file in /etc/profile.d/oracle.sh that includes

    export ORACLE_HOME=/opt/ora/instantclient_11_2 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME 

    Create a file in /etc/ld.so.conf.d/oracle.conf that includes

    /opt/ora/instantclient_11_2 

    Execute the following command

    sudo ldconfig 

    Note: you may need to reboot to apply settings

  5. Create a symlink

    cd $ORACLE_HOME  ln -s libclntsh.so.11.1 libclntsh.so 
  6. Install cx_Oracle python package

    • You may install using pip

      pip install cx_Oracle 
    • Or install manually

      Download the cx_Oracle source zip that corresponds with your Python and Oracle version. Then expand the archive, and run from the extracted directory:

      python setup.py build  python setup.py install 
like image 150
Burhan Khalid Avatar answered Oct 14 '22 03:10

Burhan Khalid