安装说明
- 一台cents7的机器上没有安装过oracle
- python脚本需要调用远程oracle数据库,需要cx_oracle数据库
python3.9 /data/script/datasec/test.py
#产生报错
....
File "/data/script/datasec/newSQL.py", line 3, in <module>
import cx_Oracle
ModuleNotFoundError: No module named 'cx_Oracle'
- 这个cx_Oracle驱动非常不好装
- 以下是安装cx_Oracle的标准步骤
安装Oracle客户端
wget "https://download.oracle.com/otn/linux/instantclient/11204/oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm"
rpm -ivh oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm
ll /usr/lib/oracle/11.2/client64/lib/
total 183252
-rw-r--r-- 1 root root 53865194 Aug 25 2013 libclntsh.so.11.1
-rw-r--r-- 1 root root 7996693 Aug 25 2013 libnnz11.so
-rw-r--r-- 1 root root 1973074 Aug 25 2013 libocci.so.11.1
-rw-r--r-- 1 root root 118738042 Aug 25 2013 libociei.so
-rw-r--r-- 1 root root 164942 Aug 25 2013 libocijdbc11.so
-rw-r--r-- 1 root root 2091135 Aug 25 2013 ojdbc5.jar
-rw-r--r-- 1 root root 2739616 Aug 25 2013 ojdbc6.jar
-rw-r--r-- 1 root root 66779 Aug 25 2013 xstreams.jar
cd /usr/lib/oracle/11.2/client64/lib/
$ ln -s libclntsh.so.11.1 libclntsh.so
- 验证完毕,oracle客户端安装好了
- 记住
/usr/lib/oracle/11.2/client64/lib/
这个目录,后面还要用到
安装Oracle的SDK
- 还是刚才的oracle下载页里,往下拉一屏,找到sdk的下载项,这次我们下载zip格式就行
wget https://download.oracle.com/otn/linux/instantclient/11204/instantclient-sdk-linux.x64-11.2.0.4.0.zip
unzip instantclient-sdk-linux.x64-11.2.0.4.0.zip
Archive: instantclient-sdk-linux.x64-11.2.0.4.0.zip
creating: instantclient_11_2/sdk/
creating: instantclient_11_2/sdk/include/
inflating: instantclient_11_2/sdk/include/occi.h
inflating: instantclient_11_2/sdk/include/occiCommon.h
inflating: instantclient_11_2/sdk/include/occiControl.h
inflating: instantclient_11_2/sdk/include/occiData.h
inflating: instantclient_11_2/sdk/include/occiObjects.h
inflating: instantclient_11_2/sdk/include/occiAQ.h
inflating: instantclient_11_2/sdk/include/oci.h
inflating: instantclient_11_2/sdk/include/oci1.h
inflating: instantclient_11_2/sdk/include/oci8dp.h
inflating: instantclient_11_2/sdk/include/ociap.h
inflating: instantclient_11_2/sdk/include/ociapr.h
inflating: instantclient_11_2/sdk/include/ocidef.h
inflating: instantclient_11_2/sdk/include/ocidem.h
inflating: instantclient_11_2/sdk/include/ocidfn.h
inflating: instantclient_11_2/sdk/include/ociextp.h
inflating: instantclient_11_2/sdk/include/ocikpr.h
inflating: instantclient_11_2/sdk/include/ocixmldb.h
inflating: instantclient_11_2/sdk/include/ocixstream.h
inflating: instantclient_11_2/sdk/include/odci.h
inflating: instantclient_11_2/sdk/include/oratypes.h
inflating: instantclient_11_2/sdk/include/ori.h
inflating: instantclient_11_2/sdk/include/orid.h
inflating: instantclient_11_2/sdk/include/orl.h
inflating: instantclient_11_2/sdk/include/oro.h
inflating: instantclient_11_2/sdk/include/ort.h
inflating: instantclient_11_2/sdk/include/xa.h
inflating: instantclient_11_2/sdk/include/nzt.h
inflating: instantclient_11_2/sdk/include/nzerror.h
inflating: instantclient_11_2/sdk/include/ldap.h
creating: instantclient_11_2/sdk/demo/
inflating: instantclient_11_2/sdk/demo/demo.mk
inflating: instantclient_11_2/sdk/demo/cdemo81.c
inflating: instantclient_11_2/sdk/demo/occidemo.sql
inflating: instantclient_11_2/sdk/demo/occidemod.sql
inflating: instantclient_11_2/sdk/demo/occidml.cpp
inflating: instantclient_11_2/sdk/demo/occiobj.cpp
inflating: instantclient_11_2/sdk/demo/occiobj.typ
inflating: instantclient_11_2/sdk/SDK_README
extracting: instantclient_11_2/sdk/ottclasses.zip
inflating: instantclient_11_2/sdk/ott
- 将解压出来的
instantclient_11_2/sdk
copy到刚才安装客户端后出来的文件夹中
cp -r sdk /usr/lib/oracle/11.2/client64/lib/
ll /usr/lib/oracle/11.2/client64/lib/
total 183252
-rw-r--r-- 1 root root 53865194 Aug 25 2013 libclntsh.so.11.1
-rw-r--r-- 1 root root 7996693 Aug 25 2013 libnnz11.so
-rw-r--r-- 1 root root 1973074 Aug 25 2013 libocci.so.11.1
-rw-r--r-- 1 root root 118738042 Aug 25 2013 libociei.so
-rw-r--r-- 1 root root 164942 Aug 25 2013 libocijdbc11.so
-rw-r--r-- 1 root root 2091135 Aug 25 2013 ojdbc5.jar
-rw-r--r-- 1 root root 2739616 Aug 25 2013 ojdbc6.jar
drwxr-xr-x 4 root root 84 Aug 25 2013 sdk
-rw-r--r-- 1 root root 66779 Aug 25 2013 xstreams.jar
- 这步没有安装,准确的说是下载解压Oracle_sdk文件,不需要验证
安装cx_oracle
export ORACLE_HOME=/usr/lib/oracle/11.2/client64/lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME
pip3.9 install cx_Oracle
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting cx_Oracle
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/63/23/d495b40eb7950e8c4d3a8f22a92552b5d173b92479c60ad7f9355ad51666/cx_Oracle-8.3.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (888 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 888.2/888.2 kB 9.9 MB/s eta 0:00:00
Installing collected packages: cx_Oracle
Successfully installed cx_Oracle-8.3.0
$ python3.9
$ import cx_Oracle
cx_oracle配置
# cat /etc/ld.so.conf.d/oracle.conf
cat: /etc/ld.so.conf.d/oracle.conf: No such file or directory
# echo /usr/lib/oracle/11.2/client64/lib > /etc/ld.so.conf.d/oracle.conf
# ldconfig
>> Home