Python | cx_Oracle | DPI-1047报错处理(Win\Mac\Linux)
测试代码
import cx_Oracle
# 建立与 Oracle 数据库的连接
connection = cx_Oracle.connect("{login}/{passwd}@{IP}:{PORT}/{Service Name}")
# 创建游标
cursor = connection.cursor()
# 执行 SQL 查询
cursor.execute("SELECT table_name FROM user_tables")
# 获取查询结果
result = cursor.fetchall()
# 处理查询结果
for row in result:
# 处理每一行数据
print(row)
# 提交事务(如果需要)
connection.commit()
# 关闭游标和数据库连接
cursor.close()
connection.close()
报错信息
Traceback (most recent call last):
File "~/test_oracle.py", line 4, in <module>
connection = cx_Oracle.connect("xxx/xxx@xxx:xxx/xxx")
cx_Oracle.DatabaseError: DPI-1047: Cannot locate a 64-bit Oracle Client library: "dlopen(libclntsh.dylib, 0x0001): tried: 'libclntsh.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OSlibclntsh.dylib' (no such file), '/Users/py373/lib/libclntsh.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/py373/lib/libclntsh.dylib' (no such file), '/Users/py373/lib/libclntsh.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/py373/lib/libclntsh.dylib' (no such file), '/Users/anaconda". See #macos for help
解决步骤
- 报错信息的最后一点已经提到了解决方案参考:点击跳转
- 以MacOS为例(Win和Linux可参考1中文档进行操作),下载DMG文件:
cd $HOME/Downloads curl -O https://download.oracle.com/otn_software/mac/instantclient/198000/instantclient-basic-macos.x64-19.8.0.0.0dbru.dmg hdiutil mount instantclient-basic-macos.x64-19.8.0.0.0dbru.dmg /Volumes/instantclient-basic-macos.x64-19.8.0.0.0dbru/install_ic.sh hdiutil unmount /Volumes/instantclient-basic-macos.x64-19.8.0.0.0dbru
- 将文件内容全部放到python的lib库中
- 再次执行Python脚本(问题解决)
🎉如果对你有所帮助,可以点赞、关注、收藏起来,不然下次就找不到了🎉
【点赞】⭐️⭐️⭐️⭐️⭐️
【关注】⭐️⭐️⭐️⭐️⭐️
【收藏】⭐️⭐️⭐️⭐️⭐️
Thanks for watching.
–Kenny