-
#目次
-
###状況
pythonとcx_Oracleを使ってデータベースに接続したい -
###環境
- windows10
- Python 3.8.5
- cx-Oracle 8.2.1
-
###エラー内容
cx_Oracle.DatabaseError:
DPI-1047: Cannot locate a 64-bit Oracle Client library:
"The specified module could not be found".
See https://cx-oracle.readthedocs.io/en/latest/user_guide/installation.html for help
-
##エラー解決法
-
###Oracle Instant Clientをダウンロードしてない
cx_Oracleを使う場合にダウンロードが必要です。
windowsはこちらから(64bit) -
###Oracle Instant Clientのpathを正しく通せてない
pathを設定する必要がある-
環境変数の編集から設定する方法 (2のほうが簡単かも)
左下のwindowsキーを押して検索から「環境変数」と入力
環境変数を編集を選び、ユーザーの環境変数のPathから
新規でinstantclient_19_121までのpathを設定
(例: C:\Users\ユーザー名\hoge\instantclient_19_12 など) -
コードでpathをかく方法
cx_Oracle.init_oracle_client()を使ってpathを設定できる
-
環境変数の編集から設定する方法 (2のほうが簡単かも)
import cx_Oracle
lib_dir = "自分のPC内のinstantclientまでのpath"
cx_Oracle.init_oracle_client(lib_dir=lib_dir)
# フォルダーまでのpath
# pathの最初にrを付けること つけないとSyntaxErrorがでる
# (例 : r"C:\Users\ユーザー名\hoge\instantclient_19_12" )
-
###それでも解決できないとき...
自分はこの場合でしたが、デスクトップにあったinstantclient_19_12のフォルダーを
別の場所(Downloadsなど)に変えてからpathを設定すると動きました
原因はわからないです...