python與oracle數(shù)據(jù)庫進(jìn)行交互需要安裝cx_Oracle模塊和oracle客戶端
步驟如下:
1. 查看python版本號和位數(shù)

image.png
2. 下載安裝對應(yīng)的cx_Oracle
不建議直接用pip安裝,容易引發(fā)各種版本報(bào)錯
下載地址:https://pypi.org/project/cx_Oracle/5.3/#files
服務(wù)器的oracle數(shù)據(jù)庫版本是11g,所以cx_Oracle要選擇5.3-11g,并且注意與本機(jī)python的版本、位數(shù)都對應(yīng)
下載完成后運(yùn)行,按提示安裝,它將自動檢測可用的python虛擬環(huán)境,需要記住cx_Oracle安裝的目錄Installation Directory
3. 下載oracle client
到官網(wǎng)下載客戶端 http://www.oracle.com/technetwork/cn/database/features/instant-client/index-092699-zhs.html
根據(jù)python的位數(shù)選擇32位或64位:

image.png
選擇11.2.0.1版 Instant Client 程序包 — Basic:

image.png
下載后解壓,進(jìn)入instantclient_11_2目錄,將oci.dll,oraocci11.dll,oraociei11.dll這3個文件復(fù)制到上一步cx_Oracle安裝的目錄Installation Directory 下面:

image.png
環(huán)境搭建完畢,在python中import cx_Oracle,沒有報(bào)錯說明搭建成功。