Create a gist now

Instantly share code, notes, and snippets.

install cx_oracle
in progress (#1046): re-focus this page on deployment of python on linux, esp. suse; perhaps move to PythonDeployment?. for developer set-up, see WritingQualityCode
virtualenv is a tool to create isolated Python environments:
The basic problem being addressed is one of dependencies and versions, and indirectly permissions. Imagine you have an application that needs version 1 of LibFoo , but another application requires version 2. How can you use both these applications? Or what if you want to install an application and leave it be ? If an application works, any change in its libraries or the versions of those libraries can break the application. ... In all these cases, virtualenv can help you.
Machine Set-Up
If your development machine runs ubuntu (or debian) linux, install with apt-get:
$ sudo apt-get install python-virtualenv
SuSE Enterprise is trickier. Even the SDK doesn't seem to have a virtualenv package. So we can install from source, starting at the python package index, then to "get pip" etc.:
> md5sum distribute_setup.py
8cf1a2b972f7345266bc9c52be3cfd21 distribute_setup.py
> sudo python distribute_setup.py
dconnolly's password:
Extracting in /tmp/tmp5lAMQe
...
> wget http://pypi.python.org/packages/source/v/virtualenv/virtualenv-1.6.4.tar.gz#md5=1072b66d53c24e019a8f1304ac9d9fc5
> tar zxf virtualenv-1.6.4.tar.gz
~/virtualenv-1.6.4> sudo python setup.py install
...
Finished processing dependencies for virtualenv==1.6.4
Mixing a repository from opensuse with SLES seems iffy, but it seems to have worked in the past:
> sudo zypper ar -f http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11/devel:languages:python.repo
> sudo zypper install python-virtualenv
Check for key fingerprint 172CCD6B0CF49B7388F1C61127163A4EEDF0D733.
Set-Up for building python extensions
Some python packages involve not just python code but a compiled extension. To compile the extension, the machine needs Python.h and the rest of the python development files.
In SuSE, these are in the python-devel package, which is on the SDK DVD. Ask InformationResources to install the package.
Python and XML
The lxml package provides a great API for working with XML in python, but it's not pure python. Before you can easy_install lxml, you'll need libxml2 and libxslt. On SuSE:
$ sudo zypper install libxml2-devel libxslt-devel
Python and Oracle
Notes on Oracle Access module
cx_Oracle is a Python extension module that allows access to Oracle databases and conforms to the Python database API specification.
The Build Hints explain how it interfaces with drivers from Oracle. The files for our 64 bit intel architecture are in Oracle instant client downloads for x86-64:
~/Downloads$ md5sum instantclient-*
7507de5158e48d7a16def5235a1b4171 instantclient-basic-linux-x86-64-11.2.0.2.0.zip
201ed479c9cfd3905cecbd213c656331 instantclient-sdk-linux-x86-64-11.2.0.2.0.zip
Once those are unzipped under /usr/local, the next step is:
$ export ORACLE_HOME=/usr/local/instantclient_11_2/
$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME
$ cd $ORACLE_HOME
$ sudo ln -s libclntsh.so.11.1 libclntsh.so
$ sudo ln -s libocci.so.11.1 libocci.so
On my Ubuntu box, I ran into ImportError: libaio.so.1: cannot open shared object file; the solution came from a December 28, 2009 post on Django and Oracle support:
$ sudo apt-get install -y libaio1
Then it's pretty straightforward:
$ pip install cx_Oracle
Downloading/unpacking cx-Oracle
Running setup.py egg_info for package cx-Oracle
Installing collected packages: cx-Oracle
Running setup.py install for cx-Oracle
building 'cx_Oracle' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/local/instantclient_11_2/sdk/include -I/usr/include/python2.6 -c cx_Oracle.c -o build/temp.linux-x86_64-2.6-11g/cx_Oracle.o -DBUILD_VERSION=5.0.4
gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions build/temp.linux-x86_64-2.6-11g/cx_Oracle.o -L/usr/local/instantclient_11_2/lib -L/usr/local/instantclient_11_2/ -lclntsh -o build/lib.linux-x86_64-2.6-11g/cx_Oracle.so
Successfully installed cx-Oracle
Cleaning up...
Download in other formats:
Plain Text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment