Common problems and solutions for installing cx_Oracle module in python

高洛峰
Release: 2017-02-24 15:00:49
Original
1450 people have browsed it

The examples in this article describe common problems and solutions for installing the cx_Oracle module in Python. Share it with everyone for your reference, the details are as follows:

When installing or using cx_Oracle, you need to use the Oracle link library, such as libclntsh.so.10.1, otherwise there will be various error messages .

You can get this link library by installing Oracle Instant Client, avoiding the installation of hundreds of megabytes of Oracle Client.

Software download address:

cx_Oracle’s homepage: http://cx-oracle.sourceforge.net/

Download address of required Oracle link library: http://www.oracle.com/technology/software/tech/oci/instantclient/index.html

Common errors and solutions:

1.Win32 binary installation

In Windows After installing cx_Oracle-5.0-10g.win32-py2.6.msi, when importing, an error of DLL loading failure is reported, as follows:

IDLE 2.6.1

>>> import cx_Oracle
Traceback (most recent call last):
 File "", line 1, in 
  import cx_Oracle
ImportError: DLL load failed: 找不到指定的程序。
Copy after login

Solution:

Download instantclient-basic-win32-10.2.0.4.zip from the Oracle site, unzip it, and copy the oci.dll file Go to Lib/site-packages in the Python installation directory, such as C:/Python26/Lib/site-packages

2. Binary installation under Linux

Under linux_x86_64, an error is reported when installing cx_Oracle-5.0.1-10g-py24-1.x86_64.rpm.

[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
Copy after login

Solution:

Reference http://www.php.cn/

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

Environment variable

vi /root/.bash_profile
Copy after login

Add the following two lines:

export ORACLE_HOME=/opt/instantclient_10_2
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME
Copy after login

Run source /root/.bash_profile Make changes take effect

Create a symbolic link to this link library

cd $ORACLE_HOME
ln -s libclntsh.so.x.x libclntsh.so
Copy after login

Restart Install cx_Oracle

Be careful to add 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版本不用加--nodeps参数
Copy after login

三.Source code installation under linux

Set environment variables and symbolic links as above. To install source code under linux_x86_64, run python setup.py build. The error message during compilation 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: passing parameter 1 Converting between incompatible pointer types when passing argument 2 (of 'Environment_CheckForError')
Connection.c:1172: warning: Converting between incompatible pointer types when passing argument 2 (of 'Environment_CheckForError')
Connection.c :1172: Error: Too many arguments supplied to function 'Environment_CheckForError'
Connection.c:1176: Error: 'udt_Connection' has no member named 'sessionHandle'

Solution:

This error does not occur in version 5.0.3. Please note that there must be an include directory under ORACLE_HOME. This directory must contain the source files required for compilation. The source files are not available in the Oracle Instant Client. Include. I copied it from the directory D:/oracle/product/10.2.0/client_1/oci/include on the Windows client.

4.Import error

>>> import cx_Oracle
Traceback (most recent call last):
 File "", 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 "", 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
>>>
Copy after login

This is because of the limitations of SELinux, run as follows Command to cancel the restriction:

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

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
Copy after login

It is still a limitation of SELinux, set SELinux to disabled

Turn off selinux:

Run the command: vim /etc/selinux/config

Change selinux=enforcing or permissive to disabled
Run the command: setenforce 0

6. There is a problem with the UNICODE installation package

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
Copy after login

It is currently found that the 5.0.3 version of the package will cause an error when executing SQL. It is not recommended to use it. If you replace it with a non-UNICODE package, there will be no problem.

For more articles related to common problems and solutions for python installation cx_Oracle module, please pay attention to the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!