Errors and solutions encountered when installing cx_Oracle

Y2J
Release: 2017-05-08 16:51:10
Original
3154 people have browsed it

This article mainly introduces the common problems and solutions for installing the cx_Oracle module in Python. It gives examples and analyzes the common problems, solutions and related precautions for installing the cx_Oracle module in Python on the Windows platform and Linux platform. Friends in need can refer to the following

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: cx-oracle.sourceforge.net/
Download of necessary Oracle link libraries Address: www.oracle.com/technology/software/tech/oci/instantclient/index.html

Common errors and solutions:

一.win32 binary installation

After installing cx_Oracle-5.0-10g.win32-py2.6.msi under windows, when importing, it reports that DLL is loading The failed error is 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: 找不到指定的程序。
Copy after login

Solution:

Download instantclient-basic-win32-10.2 from the Oracle site. 0.4.zip, after decompression, copy the oci.dll file 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 occurs 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:

Refer to cx-oracle.sourceforge.net/BUILD.txt

Download basic-10.2.0.4 from the Oracle site. 0-linux-x86_64.zip to the /opt directory and unzip it, you will see libclntsh.so.10.1 in the /opt/instantclient_10_2 directory

Set environment variables

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 to make the changes take effect

Establish a symbolic link to this link library

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

Reinstall 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

3. Source code installation under Linux

Set the environment variables and symbolic links as above, install the 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 (of 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 a include directory under ORACLE_HOME. There must be The source files required for compilation are not included in the Oracle Instant Client. 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 "<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
>>>
Copy after login

This is because of the restrictions of SELinux. Run the following command to cancel the restrictions:

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. UNICODE There is a problem with the 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

[Related recommendations]

1. Python Free Video Tutorial

2. Application of Python in Data Science

3. Basic Introduction to Python Tutorial

The above is the detailed content of Errors and solutions encountered when installing cx_Oracle. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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!