开发者

python and Oracle

开发者 https://www.devze.com 2022-12-12 17:12 出处:网络
I would like to be able to connect to Oracle 10.1.0.2.0 (which is installed on different machine) via python.

I would like to be able to connect to Oracle 10.1.0.2.0 (which is installed on different machine) via python.

My comp is running on Ubuntu 9.04 Jaunty with Python 2.6 installed.

I have downloaded and unpacked instantclient-basic-linux32-10.1.0.5-20060511.zip , set LD_LIB开发者_如何学JAVARARY_PATH and ORACLE_HOME to point to the directory where I unpacked it. Then I've downloaded cx_Oracle-5.0.2-10g-py26-1.i386.rpm and installed it:

$sudo alien -i cx_Oracle-5.0.2-10g-py26-1.i386.rpm

When I run

$python -c 'import cx_Oracle'

I get:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: /usr/lib/python2.6/cx_Oracle.so: undefined symbol: OCIClientVersion

Help would be very appreciated.


I believe OCIClientVersion requires Oracle 10g release 2, but you're using release 1.

It looks like cx_Oracle binary you downloaded has been compiled with -DORACLE_10GR2 which makes it include the OCIClientVersion call. Since this is a compile-time-only option there should really be downloads for 10g and 10gR2 separately, but it would seem there aren't:

This module has been built with Oracle 9.2.0, 10.2.0, 11.1.0 on Linux

So you may have to download the cx_Oracle sources and build them yourself. (Consequently you'll need the Python and Oracle client headers.)

Alternatively you could try the cx_Oracle build for Oracle 9i instead. This sounds a bit dodgy but is apparently supposed to work.


Thanks to bobince for his answer, I will just try to summarize possible solutions to make it more readable for the others.

Both LD_LIBRARY_PATH and ORACLE_HOME need to point to directory where Oracle InstantClient is unpacked.

  • You can use cx_Oracle 4.4.1 for Oracle 9i together with Oracle InstantClient 10.1

After installing cx_Oracle 4.4.1

sudo alien -i cx_Oracle-4.4.1-9i-py26-1.i386.rpm

cx_Oracle.so is placed in /usr/local/lib/python2.6/site-packages, so following symbolic link needs to be created

sudo ln -s /usr/local/lib/python2.6/site-packages/cx_Oracle.so /usr/lib/python2.6

Also since you are using cx_Oracle for Oracle 9i you need to create symbolic link in the InstantClient directory

sudo ln -s libclntsh.so.10.1 libclntsh.so.9.0
  • Alternatively you can use cx_Oracle 5.0.2 for Oracle 10g with Oracle InstantClient 10.2

Installation procedure is similar.

sudo alien -i cx_Oracle-5.0.2-10g-py26-1.i386.rpm
sudo ln -s /usr/lib/python2.6/site-packages/cx_Oracle.so /usr/lib/python2.6
  • Building cx_Oracle 10g sources to work with Oracle InstantClient 10.1 is not an option since cx_Oracle 10g uses code specific to Oracle 10g Release 2.

Note: It is hard to predict whether these solutions work without any flaws (further testing is needed).

0

精彩评论

暂无评论...
验证码 换一张
取 消