python使用cx_oracle连接oracle数据库

http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html---下载instantclient-basic-linux.x64-11.2.0.4.0
http://sourceforge.net/projects/cx-oracle/files/5.1.2/----下载cx_Oracle-5.1.2.tar.gz
https://pypi.python.org/pypi/cx_Oracle----下载cx_Oracle-5.1.2.tar.gz
linux版本		CentOS release 6.5 (Final)
python版本	2.6.6
oracle版本		11.2.0.4 x86_64

1、安装oracle客户端和sdk
# unzip instantclient-basic-linux.x64-11.2.0.4.0.zip
# cp ~/instantclient_11_2/* /usr/local/oracle_instantclient_11.2.0.4_x86_64/
http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html---下载instantclient-basic-linux.x64-11.2.0.4.0
http://sourceforge.net/projects/cx-oracle/files/5.1.2/----下载cx_Oracle-5.1.2.tar.gz
https://pypi.python.org/pypi/cx_Oracle----下载cx_Oracle-5.1.2.tar.gz
linux版本		CentOS release 6.5 (Final)
python版本	2.6.6
oracle版本		11.2.0.4 x86_64

1、安装oracle客户端和sdk
# unzip instantclient-basic-linux.x64-11.2.0.4.0.zip
# cp ~/instantclient_11_2/* /usr/local/oracle_instantclient_11.2.0.4_x86_64/

# unzip instantclient-sdk-linux.x64-11.2.0.4.0.zip -d /usr/local/oracle_instantclient_11.2.0.4_x86_64/
# cp -rf include/* /usr/local/oracle_instantclient_11.2.0.4_x86_64/

2、设置环境变量
# vi /etc/profile
export ORACLE_HOME=/usr/local/oracle_instantclient_11.2.0.4_x86_64
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME:/lib:/usr/lib

# source /etc/profile

3、安装cx_oracle
# tar xvf cx_Oracle-5.1.2.tar.gz 
# ln -sv /usr/local/oracle_instantclient_11.2.0.4_x86_64/libclntsh.so.11.1 /usr/local/oracle_instantclient_11.2.0.4_x86_64/libclntsh.so
# python setup.py build
# python setup.py install
Installed /usr/lib64/python2.6/site-packages/cx_Oracle-5.1.2-py2.6-linux-x86_64.egg
Processing dependencies for cx-Oracle==5.1.2
Finished processing dependencies for cx-Oracle==5.1.2

4、安装成功后进行验证
>>> import cx_Oracle




问题
1、 raise DistutilsSetupError("cannot locate an Oracle software " \
解决:需要设置oracle的环境变量LD_LIBRARY_PATH

2、cx_Oracle.c:10:17: 错误:oci.h:没有那个文件或目录
解决:安装oracle jdk

3、/usr/bin/ld: cannot find -lclntsh
解决:创建软链接
ln -sv /usr/local/oracle_instantclient_11.2.0.4_x86_64/libclntsh.so.11.1 /usr/local/oracle_instantclient_11.2.0.4_x86_64/libclntsh.so

4、cx_Oracle.DatabaseError: ORA-00972: identifier is too long和打印的中文字段名为????
# export NLS_LANG="SIMPLIFIED CHINESE_CHINA.ZHS16GBK"  ##解决了一部分问题
# export NLS_LANG="SIMPLIFIED CHINESE_CHINA.UTF8"  ##完全解决了问题

 
  

你可能感兴趣的:(python之路)