Python | cx_Oracle | DPI-1047报错处理(Win\Mac\Linux)

文章目录

  • Python | cx_Oracle | DPI-1047报错处理(Win\Mac\Linux)
    • 测试代码
    • 报错信息
    • 解决步骤

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

Python | cx_Oracle | DPI-1047报错处理(Win\Mac\Linux)_第1张图片

解决步骤

  1. 报错信息的最后一点已经提到了解决方案参考:点击跳转
  2. 以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
    
  3. 将文件内容全部放到python的lib库中
  4. 再次执行Python脚本(问题解决)
    Python | cx_Oracle | DPI-1047报错处理(Win\Mac\Linux)_第2张图片


如果对你有所帮助,可以点赞、关注、收藏起来,不然下次就找不到了


【点赞】⭐️⭐️⭐️⭐️⭐️
【关注】⭐️⭐️⭐️⭐️⭐️
【收藏】⭐️⭐️⭐️⭐️⭐️

Thanks for watching.
Kenny

你可能感兴趣的:(Python,-,基础,oracle,python,macos,DPI-1047,libclntsh.dylib)