close

遇到

cx_Oracle error. DPI-1047: Cannot locate a 64-bit Oracle Client library

要檢查是否有下載到相對應的Oracle Client library資料檔,並放入python的安裝位置

 

1. 先檢查自己連線的Oracle DB環境的Oracle版本

Select * from V$Version

2. 再依底下這篇的介紹,去下載相對應的Oracle Client library資料檔

https://cx-oracle.readthedocs.io/en/latest/user_guide/installation.html

Version 21 client libraries can connect to Oracle Database 12.1 or greater. Version 19, 18 and 12.2 client libraries can connect to Oracle Database 11.2 or greater. Version 12.1 client libraries can connect to Oracle Database 10.2 or greater. Version 11.2 client libraries can connect to Oracle Database 9.2 or greater.

3. 下載相對應的racle Client library資料檔,解壓縮後,將資料夾裡面的所有副檔名.dll全部複製進python 安裝位置

ex: D:\Program Files\Python38

就把.dll檔全部複製進去上面資料夾內

4. 測試上述步驟後的結果

import cx_Oracle

import os
import sys
import platform

try:
    
    if platform.system() == "Darwin":
        cx_Oracle.init_oracle_client(lib_dir=os.environ.get("HOME")+"/instantclient_10_2")
        
    elif platform.system() == "Windows":
        cx_Oracle.init_oracle_client(lib_dir=r"D:\Program Files\Python38")
        
    # else assume system library search path includes Oracle Client libraries
    # On Linux, must use ldconfig or set LD_LIBRARY_PATH, as described in installation documentation.
    
except Exception as err:
    print("Whoops!")
    print(err);
    sys.exit(1);

 

基本上都會成功

arrow
arrow
    文章標籤
    Python cx_Oracle
    全站熱搜
    創作者介紹
    創作者 Levi 的頭像
    Levi

    李維の私享國度

    Levi 發表在 痞客邦 留言(0) 人氣()