python本地搭建連接orcale的環境。網絡上良莠不齊。親測可用

需要環境及工具:

1、window7/10
2、Pycharm
3、python-3.6.7.exe
https://download.csdn.net/download/tlcjbl/11064521
4、cx_Oracle-5.3-11g.win32-py3.6.exe
https://download.csdn.net/download/tlcjbl/11064487
5、instantclient-basic-win32-11.2.0.1.0
https://download.csdn.net/download/tlcjbl/11064512

注意:此處python、cx_oracle、instantclient最好同時都是32/64位版本。
未知影響:因爲我本地安裝的oracle客戶端是32位,所以此處都是32位版本。

操作步驟:

1、安裝Pytharm、python、cx_oracle,解壓instantclient-basic-win32-11.2.0.1.0到某路徑。
2、將解壓後instantclient_11_2路徑下的oci.dll、oraocci11.dll、oraociei11.dll三個文件複製到python的安裝目錄下。
在這裏插入圖片描述
3、在解壓後instantclient_11_2路徑下新建文件夾,並將tnsnames.ora文件複製過來。如下圖:
在這裏插入圖片描述

4、配置環境變量
(a)新建ORACLE_HOME,變量值爲配置解壓後的instantclient_11_2路徑。
在這裏插入圖片描述
(b)在變量名爲PATH的變量值後新增python的安裝路徑、python下script文件夾路徑、 解壓後的instantclient_11_2路徑。
5、測試
在pythcarm中新建一個項目,新建一個測試的.py文件。
敲入以下代碼:

import cx_Oracle

db = cx_Oracle.connect('userName/password@IP/XXXXX')
cursor = db.cursor()
cursor.execute("select * from product_component_version")
data = cursor.fetchone()
print(data)
cursor.close()
db.close()

執行結果:
在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章