cx_Oracle imports wrong module

时间:2015-06-15 15:00:45

标签: python oracle

I am trying to connect to an Oracle DB v.9. I downloaded latest Instant Client (12.1.0.2.0) + SDK, then cx_Oracle. When trying to connect to the DB it says

cx_Oracle.DatabaseError: ORA-03134: Connections to this server version are no longer supported.

so I tried installing an older version of Instant Client 10.2.0.5:

sudo yum remove oracle-instantclient12.1-basic
sudo yum install /vagrant/oracle-instantclient-devel-10.2.0.5-1.x86_64.rpm

and updated my env:

export ORACLE_HOME=/usr/lib/oracle/10.2.0.5/client64/
export LD_LIBRARY_PATH=/usr/lib/oracle/10.2.0.5/client64/lib/

but when I try to run my Python script, cx_Oracle says:

ImportError: libclntsh.so.12.1: cannot open shared object file: No such file or directory

Of course there's no such file or directory: I have version 10.2.0.5, not 12.1. And my file is called libclntsh.so.10.1, not libclntsh.so.12.1. How do I make cx_Oracle import the right file? Or is there a way to make Instant Client v.12 work with server v.9?

2 个答案:

答案 0 :(得分:0)

Oracle guarantees backwards compatibility for two versions. So Version 10 can access version 8, 9, 10. Version 12 can only access version 10 and up.

You need to do a clean install of the correct client.

答案 1 :(得分:0)

您编译或安装的cx_Oracle是针对Oracle 12.1构建的。您将需要针对Oracle 10.2构建一个。如果确保删除旧的即时客户端并且新的即时客户端已就绪,则只需运行pip install cx_Oracle即可。现在,版本5.2及更高版本的cx_Oracle能够找到即时客户端并在没有其他帮助的情况下对其进行编译。请注意,您需要确保安装了instantclient-devel软件包才能使其正常工作。