无此类模块错误:无法加载插件:SQL炼金术,方言:oracle,oracledb

7gcisfzg  于 2022-11-03  发布在  Oracle
关注(0)|答案(1)|浏览(104)

当我尝试用SQLAlchemy连接oracle服务器时,我得到这个错误。
无此类模块错误:无法加载插件:SQL炼金术。方言:oracle。oracledb

from sqlalchemy.engine import create_engine

DIALECT = 'oracle'
SQL_DRIVER = 'oracledb'
USERNAME = 'username' #enter your username
PASSWORD = 'password' #enter your password
HOST = 'host url' #enter the oracle db host url
PORT = 1533 # enter the oracle port number
SERVICE = 'service name' # enter the oracle db service name
ENGINE_PATH_WIN_AUTH = DIALECT + '+' + SQL_DRIVER + '://' + USERNAME + ':' + PASSWORD +'@' + HOST + ':' + str(PORT) + '/?service_name=' + SERVICE

engine = create_engine(ENGINE_PATH_WIN_AUTH)

# test query

import pandas as pd
test_df = pd.read_sql_query('SELECT * FROM global_name', engine)

有什么不同连接方法吗?

mo49yndu

mo49yndu1#

为了完整性(因为答案已经在注解中):使用SQLAlchemy 1.4,将以下内容添加到顶级脚本文件中:

import sys
import oracledb
oracledb.version = "8.3.0"
sys.modules["cx_Oracle"] = oracledb

然后像使用cx_Oracle一样继续操作。
SQLAlchemy 2.0不需要此代码段

相关问题