报错信息:
Traceback (most recent call last): cx_Oracle.DatabaseError: DPI-1047: Cannot locate a 64-bit Oracle Client library: "libclntsh.so: cannot open shared object file: No such file or directory". See https://cx-oracle.readthedocs.io/en/latest/user_guide/installation.html。
各种环境:
Linux的运行环境为:3.10.0-327.el7.x86_64
python环境为3.8
Oracle version 19.0.0.0.0
报错产生原因:
使用cx_oracle是需要客户端的机器环境(本地环境)缺少client而导致报错的产生(cx_Oracle requires Oracle Client libraries. The libraries provide the necessary network connectivity to access an Oracle Database instance. They also provide basic and advanced connection management and data features to cx_Oracle. The simplest way to get Oracle Client libraries is to install the free Oracle Instant Client “Basic” or “Basic Light” package. The libraries are also available in any Oracle Database installation or full Oracle Client installation. ) cx_oracle使用详情介绍地址-https://cx-oracle.readthedocs.io/en/latest/user_guide/installation.html
报错解决:
先查看linux机器的型号 到https://www.oracle.com/database/technologies/instant-client/downloads.html 找到对应的版本进行下载,将下载的压缩包上传至虚拟机 创建文件夹 mkdir -p /opt/oraclecd /opt/oracle 将压缩包进行解压 cd /opt/oracle unzip instantclient-basic-linux.x64-21.1.0.0..zip 执行以下命令 sudo yum install libaio sudo sh -c "echo /opt/oracle/instantclient_21_1 > /etc/ld.so.conf.d/oracle-instantclient.conf" sudo ldconfig 环境变量配置 export LD_LIBRARY_PATH=/opt/oracle/instantclient_21_1:$LD_LIBRARY_PATH
在Windows下解决: 到https://www.oracle.com/database/technologies/instant-client/downloads.html 网址找到对应的版本进行下载,将下载的压缩包解压,在解压的文件夹中将oci.dll oraocci21.dll oraociei.dll三个文件复制到python安装目录下 1.能执行则解决 2.未解决须配置环境变量