Installation cx_Oracle oracle database connection Python3 practical operation summary

Clarify version, the most important! ! !

When first installed configuration, you must grasp a point, that is the same version! Including: system version, python version, version oracle client, cx_Oracle version, and then install configuration is easy!

If you have installed Python, check your installed version of Python is the number of bits:

Of course, your 64-bit operating system also can install 32-bit development environment. Not vice versa! Remember!

oracle client version, cx_Oracle version corresponds to the version of Python and digits:

such as:

Python Version: Python3.4.3 32 place;

cx_Oracle version: cx_Oracle-5.2-11g.win32-py3.4

Version of the oracle client: instantclient-basic-win32-11.2.0.1.0;

There are also three points Note:

Version corresponding to the number of bits are 32;

cx_Oracle and the corresponding python version, is 3.4;

cx_Oracle instantclient and corresponding version, is 11;    ,

Again (Biexian my long-winded, it is important to figure out): for example, my system is win7 64-bit, python version is 32-bit, so download and install the Oracle Client is 32 11g-bit, corresponding cx_Oracle will have to be 32 11g position, of course, also pay attention to the python version, this python2.X or python3.X, but also the corresponding version.

With this in mind understand, we must be prepared to install.

cx_Oracle installation

Download: https://pypi.python.org/pypi/cx_Oracle/5.3  Download low version cx_Oracle version I downloaded cx_Oracle-5.3-11g.win32-py3.6.exe, simply double-click install after downloading, ok.

Not recommended for direct use pip install cx_Oracle command to install, easy error because the version of the problem. cx_Oracle error: cx_Oracle.DatabaseError: DPI-1050: Oracle Client library must be at version 11.2, which is caused by too much cx_Oracle version.

oracle client

Download: http: //www.oracle.com/technetwork/database/features/instant-client/index-097480.html

Unzip the downloaded file, copy oci, oraocci11, oraociei11 the three DLL paste it into your PY Libs directory / site-packages folder.

python3.4 oracle database connection test code:

?
1
2
3
4
5
6
7
8
9
10
import cx_Oracle
 
conn = cx_Oracle.connect( '用户名/密码@主机ip地址/orcl' )   #用自己的实际数据库用户名、密码、主机ip地址 替换即可
curs = conn.cursor()
sql = 'SELECT * FROM 。。。' #sql语句
rr = curs.execute (sql)
row = curs.fetchone()
print (row[ 0 ])
curs.close()
conn.close()

  

With a ORACLE_HOME environment variable to point Instant Client directory (if you are already successfully connected to this orcale database, and environment variables This step can not, as the case may execute):

They want to put down the path, I is C: \ instantclient-basic-win32-11.2.0.1.0 \ instantclient_11_2

And then configure the environment variables: Right Computer - Properties - Advanced System Settings - Environment Variables - System Variables - New

  Variable: ORACLE_HOME value: Q: \ OracleClient

  Variable: TNS_ADMIN value: Q: \ OracleClient

  Edit path with ';' separated by a plus Q: \ OracleClient

 

Installation is complete, the entire installation process is very simple, but also many failures of my own summary, I hope to help you!

 

add another point:

oracle database server version if it is 64, the median client installed on your machine is 32 or 64, it does not affect use.

Oracle server without installing the machine.

When first installed configuration, you must grasp a point, that is the same version! Including: system version, python version, version oracle client, cx_Oracle version, and then install configuration is easy!

If you have installed Python, check your installed version of Python is the number of bits:

Of course, your 64-bit operating system also can install 32-bit development environment. Not vice versa! Remember!

oracle client version, cx_Oracle version corresponds to the version of Python and digits:

such as:

Python Version: Python3.4.3 32 place;

cx_Oracle version: cx_Oracle-5.2-11g.win32-py3.4

Version of the oracle client: instantclient-basic-win32-11.2.0.1.0;

There are also three points Note:

Version corresponding to the number of bits are 32;

cx_Oracle and the corresponding python version, is 3.4;

cx_Oracle instantclient and corresponding version, is 11;    ,

Again (Biexian my long-winded, it is important to figure out): for example, my system is win7 64-bit, python version is 32-bit, so download and install the Oracle Client is 32 11g-bit, corresponding cx_Oracle will have to be 32 11g position, of course, also pay attention to the python version, this python2.X or python3.X, but also the corresponding version.

With this in mind understand, we must be prepared to install.

cx_Oracle installation

Download: https://pypi.python.org/pypi/cx_Oracle/5.3  Download low version cx_Oracle version I downloaded cx_Oracle-5.3-11g.win32-py3.6.exe, simply double-click install after downloading, ok.

Not recommended for direct use pip install cx_Oracle command to install, easy error because the version of the problem. cx_Oracle error: cx_Oracle.DatabaseError: DPI-1050: Oracle Client library must be at version 11.2, which is caused by too much cx_Oracle version.

oracle client

Download: http: //www.oracle.com/technetwork/database/features/instant-client/index-097480.html

Unzip the downloaded file, copy oci, oraocci11, oraociei11 the three DLL paste it into your PY Libs directory / site-packages folder.

python3.4 oracle database connection test code:

?
1
2
3
4
5
6
7
8
9
10
import cx_Oracle
 
conn = cx_Oracle.connect( '用户名/密码@主机ip地址/orcl' )   #用自己的实际数据库用户名、密码、主机ip地址 替换即可
curs = conn.cursor()
sql = 'SELECT * FROM 。。。' #sql语句
rr = curs.execute (sql)
row = curs.fetchone()
print (row[ 0 ])
curs.close()
conn.close()

  

With a ORACLE_HOME environment variable to point Instant Client directory (if you are already successfully connected to this orcale database, and environment variables This step can not, as the case may execute):

They want to put down the path, I is C: \ instantclient-basic-win32-11.2.0.1.0 \ instantclient_11_2

然后是配置环境变量:右键计算机——属性——高级系统设置——环境变量——系统变量——新建

  变量:ORACLE_HOME  值:Q:\OracleClient

  变量:TNS_ADMIN       值:Q:\OracleClient

  编辑path用';'隔开加一个  Q:\OracleClient

 

安装结束,整个安装过程非常简单,也是我自己多次失败的总结,希望对你有帮助!

 

补充一点:

oracle数据库服务端版本如果是64位,你的机子上安装的客户端位数是32还是64,都不影响使用。

本机上不需要安装oracle服务端。

Guess you like

Origin www.cnblogs.com/mmz-tester/p/11122165.html