使用Python3 for mac上面的cx_Oracle數據庫驅動html
Instant Client 下載適用於 Mac OS X (Intel x86)python
這裏版本的選擇,應該根據你訪問的oracle庫的版原本選擇。git
ORACLE_HOME=/usr/local/oracle/instantclient_11_2 LD_LIBRARY_PATH=$ORACLE_HOME VERSION=11.2.0.3.0 ARCH=x86_64 DYLD_LIBRARY_PATH=/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/clidriver/lib:$ORACLE_HOME export ORACLE_HOME export LD_LIBRARY_PATH export VERSION export ARCH export DYLD_LIBRARY_PATH
**Note:**這裏的DYLD_LIBRARY_PATH須要留意,若是這裏配置失誤,會致使Python找不到相關庫,以下錯誤:github
>>> import cx_Oracle Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/cx_Oracle.cpython-36m-darwin.so, 2): Library not loaded: /ade/b/2649109290/oracle/rdbms/lib/libclntsh.dylib.11.1 Referenced from: /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/cx_Oracle.cpython-36m-darwin.so Reason: image not found
mkdir -p /usr/local/oracle/ cd /usr/local/oracle/ tar -xzf instantclient-basic-macos.x64-11.2.0.3.0.zip tar -xzf instantclient-sdk-macos.x64-11.2.0.3.0.zip cd instantclient_11_2 ln -s libclntsh.dylib.11.1 libclntsh.dylib ln -s libocci.dylib.11.1 libocci.dylib
env ARCHFLAGS="-arch $ARCH" pip3 install cx_Oracle
zylMBP:instantclient_11_2 zhangyalin$ python3 Python 3.6.1 (v3.6.1:69c0db5050, Mar 21 2017, 01:21:04) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import cx_Oracle >>> exit()
若出現,以下狀況,則須要回頭檢查DYLD_LIBRARY_PATH環境變量:shell
zylMBP:instantclient_11_2 zhangyalin$ python3 Python 3.6.1 (v3.6.1:69c0db5050, Mar 21 2017, 01:21:04) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import cx_Oracle Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/cx_Oracle.cpython-36m-darwin.so, 2): Library not loaded: /ade/b/2649109290/oracle/rdbms/lib/libclntsh.dylib.11.1 Referenced from: /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/cx_Oracle.cpython-36m-darwin.so Reason: image not found
但願pip愈來愈好用,其實主要是我對Oracle和Python不熟悉,這裏的安裝須要事想配置好oracle的SDK纔可以比較順利的使用pip安裝oracle的驅動。數據庫
參考: Installing cx_Oracle for Python/ Mac OSX Install Oracle for Python on OSX.mdmacos