1.安装cx_Oracle
(1)在线安装
pip install cx_Oracle
(2)源码安装
下载源码:https://pypi.org/project/cx-Oracle/
tar -zxvf cx_Oracle-8.1.0.tar.gz
cd cx_Oracle-8.1.0
python setup.py install
2.测试
import cx_Oracle
导入包时未出错,当运用connect函数时,则提示错误!!
需要安装oracle客户端解决问题,这个安装oracle的轻量级客户端。
3.安装oracle
(1)安装zip包
下载地址:https://www.oracle.com/database/technologies/instant-client/linux-x86-64-downloads.html
instantclient-basiclite-linux.x64-11.2.0.4.0dbru.zip
instantclient-sdk-linux.x64-11.2.0.4.0dbru.zip
instantclient-sqlplus-linux.x64-11.2.0.4.0dbru.zip
解压文件到instanceclient_版本号:
在./network/admin/下新建tnsname.ora,并编辑:
ORCL=(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = orcl)))
配置环境变量:
export ORACLE_HOME=/home/instantclient_11_2
export PATH=$ORACLE_HOME:$PATH
export TNS_ADMIN=$ORACLE_HOME/network/admin
export LD_LIBRARY_PATH=$ORACLE_HOME:$LD_LIBRARY_PATH
(2)安装rpm包
下载:https://www.oracle.com/database/technologies/instant-client/linux-x86-64-downloads.html
rpm -ivh rpm包
#显示rpm包的安装位置
rpm -qpl oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm
如果提示RPM should not be used directly install RPM packages, use Alien instead!,需要安装alien
apt-get install alien
但是提示E: Failed to fetch http://security.ubuntu.com/ubuntu/pool/main/c/curl/curl_7.68.0-1ubuntu2.4_amd64.deb 404 Not Found [IP: 91.189.88.142 80]
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?,需要更新apt-get(命令是apt-get update),或者是忽略(--fix-misiing),这里边我更新了apt-get,然后重新执行apt-get install alien,然后
alien -i **.rpm
在./network/admin/下新建tnsname.ora,并编辑:
ORCL=(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = orcl)))
配置环境变量:
export ORACLE_HOME=/usr/lib/oracle/11.2/client64export ORACLE_SID=orclexport TNS_ADMIN=$ORACLE_HOME/network/adminexport LD_LIBRARY_PATH=$ORACLE_HOME/libexport SQLPATH=$ORACLE_HOMEPATH=$PATH:$ORACLE_HOME/bin
(3)测试远程连接
sqlplus username/paddword@ip:port/sid
提示:不要装太高版本,容易出现glibc版本较低问题,且安装不容易成功