1. 安装cx_oracle
下载:https://pypi.org/project/cx_Oracle/5.1.3/#files
[dbmon@mysql ~]$ tar -xvzf cx_Oracle-5.1.3.tar.gz
注意配置ORACLE_HOME,否则会报错
[root@mysql cx_Oracle-5.1.3]# python setup.py install
Traceback (most recent call last):
File "setup.py", line 135, in <module>
raise DistutilsSetupError("cannot locate an Oracle software " \
distutils.errors.DistutilsSetupError: cannot locate an Oracle software installation
还是报错:
[dbmon@mysql cx_Oracle-5.1.3]$ python setup.py install
running install
running build
running build_ext
building 'cx_Oracle' extension
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/dbmon/instantclient_11_2/sdk/include -I/usr/local/python-2.7.14/include/python2.7 -c cx_Oracle.c -o build/temp.linux-x86_64-2.7-11g/cx_Oracle.o -DBUILD_VERSION=5.1.3
In file included from /home/dbmon/instantclient_11_2/sdk/include/oci.h:3045,
from cx_Oracle.c:10:
/home/dbmon/instantclient_11_2/sdk/include/ociap.h:10795: warning: function declaration isn’t a prototype
/home/dbmon/instantclient_11_2/sdk/include/ociap.h:10801: warning: function declaration isn’t a prototype
gcc -pthread -shared build/temp.linux-x86_64-2.7-11g/cx_Oracle.o -L/home/dbmon/instantclient_11_2 -lclntsh -o build/lib.linux-x86_64-2.7-11g/cx_Oracle.so
/usr/bin/ld: cannot find -lclntsh
collect2: ld returned 1 exit status
error: command 'gcc' failed with exit status 1
将oracle_home中的libclntsh.so.11.1复制一份到libclntsh.so即可
[dbmon@mysql instantclient_11_2]$ cp libclntsh.so.11.1 libclntsh.so
又碰到权限问题
[dbmon@mysql cx_Oracle-5.1.3]$ python setup.py install
running install
running build
running build_ext
building 'cx_Oracle' extension
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/dbmon/instantclient_11_2/sdk/include -I/usr/local/python-2.7.14/include/python2.7 -c cx_Oracle.c -o build/temp.linux-x86_64-2.7-11g/cx_Oracle.o -DBUILD_VERSION=5.1.3
In file included from /home/dbmon/instantclient_11_2/sdk/include/oci.h:3045,
from cx_Oracle.c:10:
/home/dbmon/instantclient_11_2/sdk/include/ociap.h:10795: warning: function declaration isn’t a prototype
/home/dbmon/instantclient_11_2/sdk/include/ociap.h:10801: warning: function declaration isn’t a prototype
gcc -pthread -shared build/temp.linux-x86_64-2.7-11g/cx_Oracle.o -L/home/dbmon/instantclient_11_2 -lclntsh -o build/lib.linux-x