macOS环境配置

在下面网址中下载Oracle Instant Client

https://www.oracle.com/database/technologies/instant-client/macos-intel-x86-downloads.html

选择:instantclient-basic-macos.x64-11.2.0.4.0.zip进行下载

解压到指定目录,例如:~/oracle/instantclient_11_2然后设置环境变量

### Oracle Client
export ORACLE_HOME=~/oracle/instantclient_11_2
export DYLD_LIBRARY_PATH=$ORACLE_HOME:$PATH
export PATH=$DYLD_LIBRARY_PATH:$ORACLE_HOME:$PATH

下来建立python环境

virtualenv py3env
. bin/activate

安装cx_Oracle,如果不指定处理器架构就会出现#error architecture not supported

ARCHFLAGS="-arch x86_64" pip3 install cx_Oracle==6.0

测试程序

$ idle ora.py
import cx_Oracle

connection = cx_Oracle.connect("rwuser", "123456", "127.0.0.1/xe")
cursor = connection.cursor()
cursor.execute("select table_name from all_tables")
for tname in cursor:
    print("Values:", tname)

运行测试

python3 ora.py

[ 编辑 | 历史 ]
最近由“jilili”在“2021-03-13 16:22:12”修改