- python3 Linux下连接oracle数据库,报错解决。
- ORA-32001:write to SPFILE reques
- Navicat Premium 12 连接Oracle
- python使用cx_Oracle连接数据库时报错: cx_Or
- python3 sqlalchemy No module nam
- Oracle系列三:在Centos下静默部署oracle11g
- Linux下,数据库意外关闭,报错ORA-27101: shar
- linux熵池耗尽,导致oracle数据库连接失败
- Python3.7 linux提交信息到Oracle 报错问题:
- python3 Windows下连接oracle数据库,报错解
linux环境下使用python连接Oracle需要使用cx-Oracle和instantclient-。
一、安装cx_Oracle
外网环境直接
pip install cx_Oracle
内网环境
去官网上下载wheel文件,导入内网环境后install
import cx_Oracle
conn = cx_Oracle.connect(rkcx_zhanghao/rkcx_mima@10.64.54.93:31521/rkqry)
直接运行会报错
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".
是因为环境变量配置不正确,导致libclntsh.so这个文件没有找到
一、Oracle Instant Client
检查Oracle数据库的版本以及系统类型下载相应的文件!!!
我的oracle是11.2.0版本的对应下载压缩包:
linux环境客户端需要依赖 libaio yum install libaio
然后新建一个文件夹
mkdir -p /home/test/oracle
压缩包移过去后,解压
unzip instantclient-basic-linux.x64-11.2.0.4.0.zip
解压完成后,生成新生成的文件夹 instantclient_11_2
新增环境配置,在用户路径下 ls -a 查看 .bash_profile文件。
系统配置为
[test@tandel_191 ~]# vim /etc/.bash_profile
只为当前用户配置为
[test@tandel_191 ~]# vim /home/test/.bash_profile
打开文件后
在~/.bash_profile文件末尾加入以下内容
export LD_LIBRARY_PATH=/home/test/oracle/instantclient_11_2:$LD_LIBRARY_PATH
如果python输出字符串乱码或报错,在~/.bash_profile后添加
export LC_ALL='en_US.UTF-8'
编辑完成后,激活配置的文件
[test@tandel_191 ~]source /home/test/.bash_profile
然后可以查看刚刚配置的环境路径是否正确
[test@tandel_191 ~]echo $LD_LIBRARY_PATH
网友评论