python common problems and solutions for installing the cx_Oracle module

  • 2020-05-26 09:35:41
  • OfStack

This article illustrates common problems and solutions for installing the cx_Oracle module for python. I will share it with you for your reference as follows:

When installing or using cx_Oracle, you need to use Oracel's link library, such as libclntsh.so.10.1, otherwise you will have all kinds of error messages.

This link library can be obtained by installing Oracle Instant Client instead of the hundreds of megabytes of Oracle Client.

Software download address:

cx_Oracle homepage: http:// cx-oracle.sourceforge.net /
Necessary Oracle link library download address: http: / / www oracle. com technology/software/tech/oci/instantclient/index html

Common mistakes and solutions:

1.win322 installation

After installing cx_Oracle-5.0-10g. win32-py2.6.msi under windows, when importing, the error that DLL failed to load is reported as follows:

IDLE 2.6.1


>>> import cx_Oracle
Traceback (most recent call last):
 File "<pyshell#0>", line 1, in <module>
  import cx_Oracle
ImportError: DLL load failed:  The specified program could not be found. 

Solutions:

Downloaded from instantclient Oracle site - basic - win32-10.2.0.4. zip, decompression, will the oci. dll file to Python Lib/site - packages installation directory, such as C: / Python26 / Lib/site - packages

2.linux under base 2 installation

Under linux_x86_64, install cx_Oracle-5.0.1-10g-py24-1.x86_64.rpm times error.


[root@BJ-UPDATE-01 ~]# rpm -ivh cx_Oracle-5.0.1-10g-py24-1.x86_64.rpm
error: Failed dependencies:
    libclntsh.so.10.1()(64bit) is needed by cx_Oracle-5.0.1-1.x86_64

Solutions:

Reference http: / / cx - oracle sourceforge. net/BUILD txt

Download basic-10.2.0.4.0-linux-x86_64.zip from the Oracle site and unzip to /opt. You will see libclntsh.so.10.1 in /opt/instantclient_10_2

Setting environment variables


vi /root/.bash_profile

Add the following two lines:


export ORACLE_HOME=/opt/instantclient_10_2
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME

Run source /root/.bash_profile for the changes to take effect

Create symbolic links for this link library


cd $ORACLE_HOME
ln -s libclntsh.so.x.x libclntsh.so

Reinstall cx_Oracle

Note the --nodeps parameter, otherwise the above error will be reported


[root@BJ-UPDATE-01 ~]# rpm -ivh --nodeps cx_Oracle-5.0.1-10g-py24-1.x86_64.rpm
#5.0.3 Version not added --nodeps parameter 

3. Source code installation under linux

Set the environment variables and symbolic links as shown above, run python setup.py build under linux_x86_64 source code installation, and the error message at compile time is as follows:

Connection.c:1169: warning: statement does not work
Connection.c :1171: error: 'udt_Connection' has no member named 'environment'
Connection.c :1172: warning: converts between incompatible pointer types when passing parameter 1 (belonging to 'Environment_CheckForError')
Connection.c :1172: warning: converts between incompatible pointer types when passing parameter 2 (belonging to 'Environment_CheckForError')
Connection.c :1172: error: too many arguments are supplied to the function 'Environment_CheckForError'
Connection.c :1176: error: 'udt_Connection' has no member named 'sessionHandle'

Solutions:

This error did not appear in version 5.0.3. Please note that ORACLE_HOME has the include directory under ORACLE_HOME, and this directory should have the source files required for compilation. The source files are not included in the Oracle Instant Client client. I'm from windows client D: / oracle/product / 10.2.0 / client_1 / oci/include copy this directory.

4. import errors


>>> import cx_Oracle
Traceback (most recent call last):
 File "<stdin>", line 1, in ?
ImportError: /usr/lib/oracle/10.2.0.4/client64//lib/libnnz10.so: cannot restore segment prot after reloc: Permission denied
>>> import cx_Oracle
Traceback (most recent call last):
 File "<stdin>", line 1, in ?
ImportError: /usr/lib/oracle/10.2.0.4/client64//lib/libclntsh.so.10.1: cannot restore segment prot after reloc: Permission denied
>>> import cx_Oracle
>>>

This is because of SELinux restrictions, run the following command to remove the restrictions:


chcon -t texrel_shlib_t cd $ORACLE_HOME/libnnz10.so
chcon -t texrel_shlib_t cd $ORACLE_HOME/libclntsh.so.10.1

5. Runtime error


Traceback (most recent call last):
 File "oracle_conn.py", line 9, in ?
  connection = cx_Oracle.Connection(u"oracle/oracle123@CCIP")
cx_Oracle.InterfaceError: Unable to acquire Oracle environment handle

Again, set SELinux to disabled

Turn off the selinux:

Run the command: vim /etc/selinux/config
Change selinux=enforcing or permissive to disabled
Run command: setenforce 0

6. There is a problem with the installation package of UNICODE


Traceback (most recent call last):
 File "./oracle_conn.py", line 22, in ?
  folderIds=cursor.fetchmany(10)
cx_Oracle.DatabaseError: OCI-22061: Message 22061 not found; No message file for product=RDBMS, facility=OCI; arguments: [T

Currently, it is found that the 5.0.3 version of the package will cause an error when executing SQL, so it is not recommended to use it. It is ok to replace it with a non-UNICODE package.

More about Python related content interested readers to view this site project: Python coding skills summary, Python pictures skills summary, "Python data structure and algorithm tutorial", "Python Socket programming skills summary", "Python function using techniques", "Python string skills summary", "Python introduction and advanced tutorial" and "Python file and directory skills summary"

I hope this article is helpful to you Python programming.


Related articles: