FAQs and solutions for installing the cx_Oracle module in python

Source: Internet
Author: User
This article mainly introduces the common problems and solutions for installing the cx_Oracle module in python, and provides examples to analyze the common problems, solutions, and precautions for installing the cx_Oracle module on the Windows and Linux platforms, for more information about how to install the cx_Oracle module in python, see the following example. We will share this with you for your reference. The details are as follows:

When you install or use cx_Oracle, you need to use the connector El library, such as libclntsh. so.10.1. Otherwise, there will be various error messages.

After installing the Oracle Instant Client, you can get this link library to avoid installing a massive Oracle Client of hundreds of megabytes.

Software:

Cx_Oracle home: http://cx-oracle.sourceforge.net/

Required Oracle linked Library: http://www.oracle.com/technology/software/tech/oci/instantclient/index.html

Common errors and solutions:

1. win32 binary installation

After the cx_Oracle-5.0-10g.win32-py2.6.msi is installed in windows, the DLL loading failure error is reported during import, as follows:

IDLE 2.6.1

>>> Import cx_OracleTraceback (most recent call last): File"
 
  
", Line 1, in
  
   
Import cx_OracleImportError: DLL load failed: the specified program cannot be found.
  
 

Solution:

Download instantclient-basic-win32-10.2.0.4.zip from the oracle site. decompress the package and copy the oci. dll file to Lib/site-packages in the Python installation directory, for example, C:/Python26/Lib/site-packages.

II. binary installation in linux

In linux_x86_64, an error is reported when installing the 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.rpmerror: Failed dependencies:    libclntsh.so.10.1()(64bit) is needed by cx_Oracle-5.0.1-1.x86_64

Solution:

Reference #

Download basic-10.2.0.4.0-linux-x86_64.zip from the oracle site to the/opt directory and decompress it. the libclntsh. so.10.1 file is in the/opt/instantclient_10_2 directory.

Set environment variables

vi /root/.bash_profile

Add the following two rows:

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

Run source/root/. bash_profile to make the change take effect.

Create a symbolic link for this link Library

cd $ORACLE_HOMEln -s libclntsh.so.x.x libclntsh.so

Reinstall cx_Oracle

Note that the -- nodeps parameter is added. 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 without adding -- nodeps parameters

3. install source code in linux

Set the environment variables and symbolic links as shown in the preceding figure. install the environment variables and symbols in the source code of linux_x86_64 and run python setup. py build. the compilation error information is as follows:

Connection. c: 1169: Warning: The statement does not work.
Connection. c: 1171: Error: 'udt _ connection' no member named 'enable'
Connection. c: 1172: Warning: Conversion between incompatible pointer types when passing parameter 1 (which belongs to 'environment _ checkforerror ')
Connection. c: 1172: Warning: transfer between incompatible pointer types when passing parameter 2 (which belongs to 'environment _ checkforerror ')
Connection. c: 1172: Error: too many arguments are provided to The 'environment _ checkforerror' function.
Connection. c: 1176: Error: 'udt _ connection' no member named 'sessionhandle'

Solution:

This error does not occur in Version 5.0.3. Note that the include directory must exist in ORACLE_HOME. the directory must contain the source files required for compilation. the source files 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.

IV. import error

>>> import cx_OracleTraceback (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_OracleTraceback (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>>>
  
 

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

chcon -t texrel_shlib_t cd $ORACLE_HOME/libnnz10.sochcon -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

Or SELinux restrictions, set SELinux to disabled

Disable selinux:

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

6. problems 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

At present, it is found that the 5.0.3 version of the package will cause an error when executing the SQL statement. it is not recommended to use it. changing to a non-UNICODE package will be okay.

For more articles about how to install the cx_Oracle module in python, refer to PHP!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.