Get the App
SLTechnology News&Howtos  ›  Database  › 

Plug-in cx_Oracle installation for python connection to Oracle

Shulou Source: shulou.com Published: 2022-06-01 06:19:46 11月01日 Update

Notes for installing cx_Oracle:

First of all, when you install the configuration, you must grasp one point, that is, the version is consistent! Including: system version, python version, oracle client version, cx_Oracle version, and then easy to install and configure!

If you have already installed Python, check how many bits are in the version of Python you installed, as follows:

> import platform

> > platform.architecture ()

View the number of version digits of the Oracle database:

SQL > select * from vandalism Banner

Oracle Database 11g Enterprise Edition Release 11.2.0.4.0-64bit

ProductionPL/SQL Release 11.2.0.4.0-ProductionCORE

11.2.0.4.0 ProductionTNS for Linux: Version 11.2.0.4.0-Production

NLSRTL Version 11.2.0.4.0-Production

Of course, your 64-bit operating system can also install a 32-bit development environment. On the contrary, no! Remember!

The version of oracle client, the version of cx_Oracle, which corresponds to the version and number of digits of Python, for example:

Python version: Python 3.5.1 64-bit

Oracle client version: instantclient-basic-linux.x64-11.2.0.4.0.zip

Choose 64-bit when choosing cx_Oracle-5.3!

Here are three more points to note:

Version digits correspond to 64 bits

Cx_Oracle and python version correspond to 3.5.1

Cx_Oracle and instantclient versions correspond to 11g

The process of installing cx_Oracle on Linux:

One: install python3

1. Prepare the compilation environment

Yum groupinstall 'Development Tools'

Yum install zlib-devel bzip2-devel openssl-devel ncurese-devel

Yum-y install gcc python-devel

two。 Download the python3.5 package

Wget https://www.python.org/ftp/python/3.5.1/Python-3.5.1.tar.xz

3. Decompress, compile

Tar Jxvf Python-3.5.1.tar.xz

Cd Python-3.5.1

. / configure-- prefix=/usr/local/python3

Make & & make install

Note the-prefix option here. Install python3 in the / usr / local / python3 directory, and the previously downloaded zip and installation packages can be deleted directly.

4. Replace the default python and pip versions of the system

Mv / usr/bin/python / usr/bin/python

2.6 establish soft links to the new python3 and PIP 3

Ln-s / usr/local/python3/bin/python3.5 / usr/bin/python

Ln-s / usr/local/python3/bin/pip3 / usr/bin/pip

Second: install the oracle client tool instantclient-basic-linux.x64-11.2.0.4.0.zip

Download address: https://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html

Download the zip package directly and decompress it!

1. Set up the installation directory of oracle

[root@dev-bibaobiao-04] # mkdir-p / data/oracle

2. Put the installation package instantclient-basic-linux.x64-11.2.0.4.0.zip under / data/oracle/, and then decompress it

[root@dev-bibaobiao-04 oracle] # unzip instantclient-basic-linux.x64-11.2.0.4.0.zip

Generate directory: / data/oracle/instantclient_11_23

3. Configure environment variables: / ect/profile or / root/.bash_profile file

Export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK

Export ORACLE_IC_HOME=/data/oracle/instantclient_11_2

Export ORACLE_HOME=$ORACLE_IC_HOME

Export TNS_ADMIN=$ORACLE_IC_HOME

Export PATH=$PATH:$HOME/bin:$ORACLE_IC_HOME

Export LD_LIBRARY_PATH=$ORACLE_IC_HOME:/usr/lib

Three: install the cx_Oracle plug-in

[root@tool202 bin] # pip install cx_Oracle

Or to prevent errors, you can choose to download the corresponding version yourself:

Https://pypi.org/project/cx_Oracle/5.3/#files

[root@tool202 python] # tar-zxvf cx_Oracle-5.3.tar.gz

[root@tool202 cx_Oracle-5.3] # python setup.py install

Tags: Version customer digit environment directory end system select configure compile plug-in no consistent operating system three variable address client that is tool Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux macOS Microsoft Xiaomi Docker