无法使用Python脚本连接到远程Oracle数据库

时间:2019-08-29 09:08:57

标签: python oracle

我无法使用python脚本连接到远程Oracle DB。我正在将以下代码编写到脚本中,并遇到如下错误:

我已经检查了以下检查点: 1. Python和Oracle客户端的版本相同,即64位 2. cx_Oracle模块安装 3.我已经下载了ODPI-C,但是我不知道该怎么办。

我正在使用MAC OSX。

代码:

import sys
import cx_Oracle
dsn_tns=cx_Oracle.makedsn('dbpx87mp.co.zing.com','1901','bpx87mp')
conn=cx_Oracle.connect('admin','Password',dsn_tns)
cur=conn.cursor()
cur.execute("select * from <table_name>")
for line in cur:
    print(line)
cur.close()
conn.close()

错误:

Traceback (most recent call last):
  File "/Users/558220/Library/Preferences/PyCharmCE2019.2/scratches/oraScript.py", line 6, in <module>

conn=cx_Oracle.connect('admin','Password',dsn_tns)
cx_Oracle.DatabaseError: DPI-1047: Cannot locate a 64-bit Oracle Client library: "dlopen(libclntsh.dylib, 1): image not found". See https://oracle.github.io/odpi/doc/installation.html#macos for help

1 个答案:

答案 0 :(得分:0)

在macOS上,不能将默认系统Python与cx_Oracle一起使用,因为该Python的权利受到限制,并且将无法加载Oracle客户端库。

通过自制软件使用Python或自己安装Python。请参阅cx_Oracle安装说明https://cx-oracle.readthedocs.io/en/latest/user_guide/installation.html#installing-cx-oracle-on-macos

相关问题