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

本地AI时代来临:Ollama + MemPalace工作流深度指南

  • u2
  • 4月 21, 2026
  • 44 views

Raycast深度解析:这个让Mac效率重装升级的东西,到底值不值?

  • u2
  • 4月 14, 2026
  • 65 views

GitHub 25K+星标!Onyx:开源可自托管的企业级AI聊天与RAG平台

  • u2
  • 4月 8, 2026
  • 170 views

InternVL-U 统一多模态模型

  • u2
  • 4月 3, 2026
  • 148 views
InternVL-U 统一多模态模型

Everything Claude Code:开源 Agent 性能优化框架

  • u2
  • 3月 31, 2026
  • 175 views

MiroFish:群体智能预测引擎,让未来在数字沙盘中预演

  • u2
  • 3月 29, 2026
  • 251 views