要安装cx_Oracle包,需要首先下载Oracle的客户端库文件和头文件。访问OTN,下载相应操作系统的Instant Client Basic Package和SDK Package。64位Linux对应的文件名分别为instantclient-basic-linux.x64-12.1.0.2.0.zipinstantclient-sdk-linux.x64-12.1.0.2.0.zip

接下来用root将这两个文件解压到/opt/oracle下:

# cd /opt
# mkdir oracle
# unzip /tmp/instantclient-basic-linux.x64-12.1.0.2.0.zip
# unzip /tmp/instantclient-sdk-linux.x64-12.1.0.2.0.zip

建立必要的符号链接:

# cd /opt/oracle/instantclient_12_1
# ln -s libclntsh.so.12.1 libclntsh.so

然后就可以安装cx_Oracle了:

$ export LD_RUN_PATH=/opt/oracle/instantclient_12_1/
$ export ORACLE_HOME=/opt/oracle/instantclient_12_1/
$ pip install cx_Oracle

(参考来源)