cx_Oracle安装

来源:互联网 发布:锐捷网络校园招聘笔试 编辑:程序博客网 时间:2024/05/16 13:52

已经先通过 anaconda 安装 了Python 2.7 (不想一个包一个包的安装 ,追求效率)

由于需要监控oracle数据库相关信息,打算通过python连接Oralce,采用cx_oracle方法

通过官方下载http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html

instantclient-basic-linux.x64-11.2.0.4.0.zip


instantclient-sdk-linux.x64-11.2.0.4.0.zip

把两个压缩文件传至服务器 /tmp目录下

#unzip instantclient-basic-linux.x64-11.2.0.4.0.zip 

#unzip instantclient-sdk-linux.x64-11.2.0.4.0.zip

# mv instantclient_11_2 /opt/

cp /opt/instantclient_11_2/* /usr/lib/    #偷懒,少配下环境变量

#vi /etc/profile

export ORACLE_HOME=/opt/instantclient_11_2
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME:$ORACLE_HOME/sdk

保存退出


source /etc/profile


然pip install cx_Oracle


Collecting cx-Oracle  Using cached cx_Oracle-5.2.tar.gzBuilding wheels for collected packages: cx-Oracle  Running setup.py bdist_wheel for cx-Oracle  Complete output from command /usr/local/anaconda2/bin/python -c "import setuptools;__file__='/tmp/pip-build-dLb_gK/cx-Oracle/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" bdist_wheel -d /tmp/tmpB6s4P0pip-wheel-:  running bdist_wheel  running build  running build_ext  building 'cx_Oracle' extension  creating build  creating build/temp.linux-x86_64-2.7-11g  gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/opt/instantclient_11_2/sdk/include -I/usr/local/anaconda2/include/python2.7 -c cx_Oracle.c -o build/temp.linux-x86_64-2.7-11g/cx_Oracle.o -DBUILD_VERSION=5.2  In file included from /opt/instantclient_11_2/sdk/include/oci.h:3045,                   from cx_Oracle.c:10:  /opt/instantclient_11_2/sdk/include/ociap.h:10795: warning: function declaration isn’t a prototype  /opt/instantclient_11_2/sdk/include/ociap.h:10801: warning: function declaration isn’t a prototype  creating build/lib.linux-x86_64-2.7-11g  gcc -pthread -shared -L/usr/local/anaconda2/lib -Wl,-rpath=/usr/local/anaconda2/lib,--no-as-needed build/temp.linux-x86_64-2.7-11g/cx_Oracle.o -L/opt/instantclient_11_2 -L/usr/local/anaconda2/lib -lclntsh -lpython2.7 -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

cd /opt/instantclient_11_2

ln -s libclntsh.so.11.1 libclntsh.so


再次安装即可



#python

>>> import cx_Oracle
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: libaio.so.1: cannot open shared object file: No such file or directory

yum install -y libaio*

测试连接

# ipython
Python 2.7.10 |Anaconda 2.4.0 (64-bit)| (default, Oct 19 2015, 18:04:42)
Type "copyright", "credits" or "license" for more information.

IPython 4.0.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: import cx_Oracle

In [2]: conn = cx_Oracle.connect("scott/tiger@172.16.254.10/nwd")
---------------------------------------------------------------------------
DatabaseError                             Traceback (most recent call last)
<ipython-input-2-13b18d27d7de> in <module>()
----> 1 conn = cx_Oracle.connect("scott/tiger@172.16.254.10/nwd")

DatabaseError: ORA-28000: the account is locked



0 0
原创粉丝点击