python cx-Oracle 驱动安装

安装oracle驱动

cx-Oracle驱动二进制版本下载地址
http://download.oracle.com/otn/linux/instantclient/185000/instantclient-basic-linux.x64-18.5.0.0.0dbru.zip
## 下载时需要oracle开发者帐号

说明:本次测试的操作系统为:Ubuntu-16.04,其他操作系统可以在oracle网站上查找并下载对应版本的zip包

mkdir -p /opt/oracle
cd /opt/oracle
unzip instantclient-basic-linux.x64-18.5.0.0.0dbru.zip
mv instantclient_18_5 /opt/oracle/
apt-get install libaio1 -y

配置:

echo /opt/oracle/instantclient_18_5 > /etc/ld.so.conf.d/oracle-instantclient.conf
ldconfig

echo “export LD_LIBRARY_PATH=/opt/oracle/instantclient_18_5:$LD_LIBRARY_PATH” >> /etc/profile.d/ora_env.sh

测试驱动连接

cat test_ora.py

import cx_Oracle
from sqlalchemy import create_engine

ip = 'xxx'
port = '1521'
uname = 'user'
pwd = 'pwd'
tnsname = 'xe'

dsnStr = cx_Oracle.makedsn(ip, port, service_name=tnsname)
connect_str = "oracle://%s:%s@%s" %(uname, pwd, dsnStr)
engine = create_engine(connect_str, encoding='utf-8')

conn = cx_Oracle.connect(uname, pwd, dsn=dsnStr)

if __name__ == '__main__':
    print(engine.url)
    import pandas as pd
    r = pd.read_sql('select * from v$version',con=engine)
    print(r)

驱动测试运行结果

python test_ora.py

oracle://user:pwd@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=IP)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=xe)))
                                               banner
 0  Oracle Database 11g Express Edition Release 11…
 1             PL/SQL Release 11.2.0.2.0 - Production
 2                       CORE\t11.2.0.2.0\tProduction
 3     TNS for Linux: Version 11.2.0.2.0 - Production
 4             NLSRTL Version 11.2.0.2.0 - Production

参考文档

https://cx-oracle.readthedocs.io/en/latest/installation.html#installing-cx-oracle-on-linux

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

u2

Related Posts

mysql连接失败:The driver has not received any packets from the server

解决java spring连接mysql报错问题,增加连接串参数

Read more

Nginx 在if语句中限制IP访问

一些web服务,出于安全考虑是不想让其他人访问到,除了添加登录用户认证外,还可以使用Nginx限制IP访问,只允许指定IP的用户访问站点或者接口。

Read more

You Missed

Google 用 AI「杀死」Google

  • u2
  • 6月 22, 2026
  • 20 views

封禁Fable 5:当美国政府成为AI的”守门人”

  • u2
  • 6月 21, 2026
  • 30 views

27亿美元没留住的人,奥特曼等了十年

  • u2
  • 6月 19, 2026
  • 37 views

OpenAI Codex 发布角色插件:当AI开始理解「分析师」和「销售」是两种不同的物种

  • u2
  • 6月 15, 2026
  • 70 views
OpenAI Codex 发布角色插件:当AI开始理解「分析师」和「销售」是两种不同的物种

TraceClaw:企业级透明可控智能体,全行为审计+零信任执行

  • u2
  • 6月 13, 2026
  • 60 views

一年前让英伟达蒸发6000亿美元的中国AI,现在被黄仁勋请上了CES的PPT

  • u2
  • 6月 7, 2026
  • 97 views