程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Connect to Oracle database under python3 Linux and solve the error.

編輯:Python

linux Environmental use python Connect Oracle Need to use cx-Oracle and instantclient.


One 、 install cx_Oracle

Internet environment direct

pip install cx_Oracle

Intranet environment
Go to Official website Upload and download wheel file , After importing the Intranet environment install

import cx_Oracle
conn = cx_Oracle.connect(rkcx_zhanghao/[email protected]:31521/rkqry)

Direct operation will report an error

cx_Oracle.DatabaseError: DPI-1047: Cannot locate a 64-bit Oracle Client library: " libclntsh.so: cannot open shared object file: No such file or directory".

This is because the environment variables are not configured correctly , Lead to libclntsh.so This file was not found


Two 、Oracle Instant Client

Oracle Official website

Check Oracle Download the corresponding files according to the database version and system type !!!
my oracle yes 11.2.0 Version of the corresponding download package :

instantclient-basic-linux.x64-11.2.0.4.0.zip

linux The environment client needs to rely on libaio yum install libaio

Then create a new folder

mkdir -p /home/test/oracle

After the compressed package is moved , decompression

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

After decompression , Generate a newly generated folder instantclient_11_2
Add environment configuration , Under the user path ls -a see .bash_profile file .

The system is configured as
[[email protected]_191 ~]# vim /etc/.bash_profile
Only for the current user
[[email protected]_191 ~]# vim /home/test/.bash_profile

After opening the file
stay ~/.bash_profile Add the following at the end of the file

export LD_LIBRARY_PATH=/home/test/oracle/instantclient_11_2:$LD_LIBRARY_PATH

If python The output string is garbled or an error is reported , stay ~/.bash_profile Add

export LC_ALL='en_US.UTF-8'

After editing , Activate the configured file

[[email protected]_191 ~]source /home/test/.bash_profile

Then you can check whether the environment path just configured is correct

[[email protected]_191 ~]echo $LD_LIBRARY_PATH


3、 ... and 、 other

Refer to the website


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved