Wednesday, September 3, 2008

Python DB2 connectivity on AIX 5.3

download python from http://www.python.org
tar -zxvf Python-2.3.7.tgz or Python-2.5.2.tar
these files may be downloaded as just .tar but they are .tar.gz and then also rename them as .gz
unzip them and untar them

cd to the Python dir
run ./configure
make symbolic links to C++ and c++ if needed

Error #1:
if ./configure gives you error error: "checking for C++ compiler default output file name. . .
configure:
error: C++ compiler cannot create executables"

make sure the xlc in the PATH (important)

also can try CC=xlc CXX=xlc ./configure

CC=xlc CXX=xlc gcc=xlc ./configure - (this worked for 2.4.5 and 2.5.2)

XLC has worked for me on AIX:
but this is just in case
./configure --without-gcc make CC=cc_r OPT="-O2 -qmaxmem=4000" install
make
make install

Installing DB2 driver now:
download ibm_db2 driver from http://pypi.python.org/pypi/ibm_db/0.3.0
ibm_db-0.3.0.tar
untar ibm_db-0.3.0.tar

set these paths first
$ . /home/db2inst1/sqllib/db2profile (path to your db2 profile)
$ export IBM_DB_DIR=/home/db2inst1/sqllib (DB_DIR PATH)
$ export IBM_DB_LIB=/home/db2inst1/sqllib/lib (DB_LLIB_PATH)

go to the untarred dir

then run
$ sudo python setup.py build
$ sudo python setup.py install

errors #1:Traceback (most recent call last): File "setup.py", line 4, in from setuptools import setup, find_packagesImportError: No module named setuptools

-- this tells you don't have setuptools module install
-- get setuptool module from http://pypi.python.org/pypi/setuptools/0.6c8
-- same process to install setuptools - untar it and run

$ sudo python setup.py build
$ sudo python setup.py install

errors #2:File "/usr/local/lib/python2.5/zipfile.py", line 325, in __init__ "Compression requires the (missing) zlib module"RuntimeError: Compression requires the (missing) zlib module
-- this tells you don't zlib module is not enabled
-- you edit /data/python/Python-2.5.2/Modules/Setup to include zlib
uncomment the #

#zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz
#*shared*

You should uncomment the zlib line, it's not enabled by default.Afterwards, you should find it in /usr/local/python1.5/lib-dynaload, or
built-in into the interpreter(if you didn't uncomment the line going '#*shared*'.)
goto /data/python/Python-2.5.2/Modules/zlib./configuremake testmake install

Important:
For zlib to work - zlibmodule.so is needed in the /usr/local/python1.5/lib-dynaload dir.
Once we make changes to the /data/python/Python-2.5.2/Modules/Setup file.
recompile python again.

Test the DB2 connectivity:
/usr/local/bin/python2.5
>>> import ibm_db
>>> conn = ibm_db.connect("dbinstance", "user", "password")

commands to try to check if the modules are picked from the right path
pythonPython 1.5.2
>>> import sys
>>> sys.path

No comments: