search
HomeBackend DevelopmentPython TutorialErrors and solutions encountered when installing cx_Oracle

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: 找不到指定的程序。

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

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

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 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

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参数

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
>>>

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

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

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

[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!

Statement
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
Python: compiler or Interpreter?Python: compiler or Interpreter?May 13, 2025 am 12:10 AM

Python is an interpreted language, but it also includes the compilation process. 1) Python code is first compiled into bytecode. 2) Bytecode is interpreted and executed by Python virtual machine. 3) This hybrid mechanism makes Python both flexible and efficient, but not as fast as a fully compiled language.

Python For Loop vs While Loop: When to Use Which?Python For Loop vs While Loop: When to Use Which?May 13, 2025 am 12:07 AM

Useaforloopwheniteratingoverasequenceorforaspecificnumberoftimes;useawhileloopwhencontinuinguntilaconditionismet.Forloopsareidealforknownsequences,whilewhileloopssuitsituationswithundeterminediterations.

Python loops: The most common errorsPython loops: The most common errorsMay 13, 2025 am 12:07 AM

Pythonloopscanleadtoerrorslikeinfiniteloops,modifyinglistsduringiteration,off-by-oneerrors,zero-indexingissues,andnestedloopinefficiencies.Toavoidthese:1)Use'i

For loop and while loop in Python: What are the advantages of each?For loop and while loop in Python: What are the advantages of each?May 13, 2025 am 12:01 AM

Forloopsareadvantageousforknowniterationsandsequences,offeringsimplicityandreadability;whileloopsareidealfordynamicconditionsandunknowniterations,providingcontrolovertermination.1)Forloopsareperfectforiteratingoverlists,tuples,orstrings,directlyacces

Python: A Deep Dive into Compilation and InterpretationPython: A Deep Dive into Compilation and InterpretationMay 12, 2025 am 12:14 AM

Pythonusesahybridmodelofcompilationandinterpretation:1)ThePythoninterpretercompilessourcecodeintoplatform-independentbytecode.2)ThePythonVirtualMachine(PVM)thenexecutesthisbytecode,balancingeaseofusewithperformance.

Is Python an interpreted or a compiled language, and why does it matter?Is Python an interpreted or a compiled language, and why does it matter?May 12, 2025 am 12:09 AM

Pythonisbothinterpretedandcompiled.1)It'scompiledtobytecodeforportabilityacrossplatforms.2)Thebytecodeistheninterpreted,allowingfordynamictypingandrapiddevelopment,thoughitmaybeslowerthanfullycompiledlanguages.

For Loop vs While Loop in Python: Key Differences ExplainedFor Loop vs While Loop in Python: Key Differences ExplainedMay 12, 2025 am 12:08 AM

Forloopsareidealwhenyouknowthenumberofiterationsinadvance,whilewhileloopsarebetterforsituationswhereyouneedtoloopuntilaconditionismet.Forloopsaremoreefficientandreadable,suitableforiteratingoversequences,whereaswhileloopsoffermorecontrolandareusefulf

For and While loops: a practical guideFor and While loops: a practical guideMay 12, 2025 am 12:07 AM

Forloopsareusedwhenthenumberofiterationsisknowninadvance,whilewhileloopsareusedwhentheiterationsdependonacondition.1)Forloopsareidealforiteratingoversequenceslikelistsorarrays.2)Whileloopsaresuitableforscenarioswheretheloopcontinuesuntilaspecificcond

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),