docker--在Anaconda jupyter 容器中使用oracle数据源时,Oracle客户端安装配置及使用示例

配置oracle 11.2 客户端

  • 将instantclient-basic-linux.x64-11.2.0.4.0.zip解压至/home/jupyter/oracle/
  • 将instantclient-sqlplus-linux.x64-11.2.0.4.0.zip解压/home/jupyter/oracle/【可选,提供sqlplus命令】
  • 复制【操作系统一般都有安装libaio.so cp /usr/lib64/libaio.so.1 /home/jupyter/oracle/instantclient_11_2/
  • ln -s /home/jupyter/oracle/instantclient_11_2/libclntsh.so.11.1 /home/jupyter/oracle/instantclient_11_2/libclntsh.so
bash 复制代码
docker run -d --rm --name=jupyter-server -p 8888:8888 \
	-e  LD_LIBRARY_PATH=/home/oracle/client:$LD_LIBRARY_PATH 
	-v /home/jupyter/notebook:/root/jupyter:rw 
	-v /home/jupyter/oracle/instantclient_11_2:/home/oracle/client 
	-v /home/jupyter/assets:/opt/conda/lib/python3.9/site-packages/notebook/static/components/pyecharts/assets:ro jupyter:2023.8.23

在jupyter中使用示例

导入依赖m

python 复制代码
import cx_Oracle
import pandas as pd
import os
from sqlalchemy import create_engine
os.environ['NLS_LANG']='SIMPLIFIED CHINESE_CHINA.UTF8'
from sqlalchemy import text

使用cursor方式

python 复制代码
conn = cx_Oracle.connect('user/pw@192.168.18.19:1521/orcl')
cursor=conn.cursor()
cursor.execute("select * from USER ")
cursor.fetchall()[0]

pandas方式

原生连接方式

python 复制代码
df=pd.read_sql("select * from USER where IS_STATUS=:status",conn,params={'status':2})
df

使用sqlalchemy方式

python 复制代码
engine = create_engine("oracle+cx_oracle://user:pw@192.168.18.19:1521/orcl",echo=False)
conn = engine.connect()
df=pd.read_sql_query(text("select * from USER where IS_STATUS=1"),con=conn)
df

碰到的坑

  • 'OptionEngine' object has no attribute 'execute'错误
  • Not an executable object:

oracle instant-client下载与安装sqlplus
Centos7-安装oracle客户端11.2.0.4
Linux系统安装oracle客户端步骤详解
sqlalchemy+pandas:错误 'OptionEngine' object has no attribute 'execute','str' object has no attribute '_execute_on_connection'

instant-client for linux-x86-64
instant-client for win64

相关推荐
ζั͡山 ั͡有扶苏 ั͡✾17 分钟前
从零搭建 Data-Juicer:一站式大模型数据预处理与可视化平台完整教程
python·data-juicer
研究司马懿31 分钟前
【ETCD】ETCD常用命令
网络·数据库·云原生·oracle·自动化·运维开发·etcd
SkylerHu43 分钟前
tornado+gunicorn部署设置max_body_size
python·tornado·gunicorn
独行soc2 小时前
2025年渗透测试面试题总结-234(题目+回答)
网络·python·安全·web安全·渗透测试·1024程序员节·安全狮
刘一说2 小时前
深入理解 Spring Boot 中的数据库迁移:Flyway 与 Liquibase 实战指南
数据库·spring boot·oracle
木头左2 小时前
年化波动率匹配原则在ETF网格区间选择中的应用
python
清空mega2 小时前
从零开始搭建 flask 博客实验(3)
后端·python·flask
August_._2 小时前
【MySQL】SQL语法详细总结
java·数据库·后端·sql·mysql·oracle
程序员小远2 小时前
7个常见的Jmeter压测问题
自动化测试·软件测试·python·测试工具·测试用例·压力测试·性能测试
红尘炼丹客2 小时前
《DeepSeek-OCR: Contexts Optical Compression》速览
人工智能·python·自然语言处理·ocr