Build an environment for Python3.3 accessing Oracle 11gR2 on CentOS6.3

Source: Internet
Author: User

Build an environment for Python3.3 accessing Oracle 11gR2 on CentOS6.3

Build an environment for Python3.3 accessing Oracle 11gR2 on CentOS6.3

View the built-in python path and version of CentOS
[Root @ oracle11g ~] # Which python
/Usr/bin/python
[Root @ oracle11g ~] # Python-V
Python 2.6.6

Download python3.3 source code package (http://www.python.org/ftp/python/3.3.2/Python-3.3.2.tar.bz2) for Installation
Tar-xvjf Python-3.3.2.tar.bz2
Cd Python-3.3.2
./Configure -- prefix = '/usr/local'
Make & make install

Set the python3 path
Ln-s/usr/local/bin/python3.3/usr/bin/python3

Here, python of the original version 2.6 is not replaced, because yum depends on python of version 2.6. To replace the yum file, you must change the yum file. For the sake of security, use python3 to represent the program of python3.3.

Python accessing Oracle generally uses a python extension module named cx_Oracle (http://cx-oracle.sourceforge.net /). Cx_Oracle then accesses Oracle through OCI. In the system environment, the Oracle client has been installed and the environment variables have been configured.

Download the latest source code package for installation.
Tar-zxvf cx_Oracle-5.1.2.tar.gz
Cd cx_Oracle-5.1.2
Python3 setup. py build
Python3 setup. py install

Use Oracle users to test the cx_Oracle Module
[Root @ oracle11g ~] # Su-oracle
[Oracle @ oracle11g ~] $ Python3
Python 3.3.2 (default, Sep 24 2013, 21:31:35)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> Import cx_Oracle
>>> Print (cx_Oracle.version)
5.1.2
>>> Quit ();

It indicates that cx_Oracle has been installed successfully.

Use the Oracle user test to connect to the database for query.
[Oracle @ oracle11g ~] $ Cat testpy. py
#! /Usr/bin/env python3
Import cx_Oracle

# Connect via SQL * Net string or by each segment in a separate argument
# Connection = cx_Oracle.connect ("user/password @ TNS ")
Connection = cx_Oracle.connect ("scott", "tiger", "V_ORCLDB ")

Cursor = connection. cursor ()
Cursor.exe cute ("""
Select sysdate col_test
From dual """)
For col_test in cursor:
Print ("Sysdate:", col_test)
[Oracle @ oracle11g ~] $ Python3 testpy. py
Sysdate: (datetime. datetime (2013, 9, 24, 23, 1, 20 ),)
[Oracle @ oracle11g ~] $

The test is successful.

You may also like the following article about Python:

Installation of Python in Linux and precautions

Install and use the Python rq module in Ubuntu 14.04

Directly run Python code without the need for the operating system

Install Python3.4 on CentOS source code

Python core programming version 2. (Wesley J. Chun). [Chinese version of hd pdf]

Python development technology details. (Zhou Wei, Zong Jie). [hd PDF scan version + book guide video + code]

Obtain Linux information using a Python script

Build a desktop algorithm transaction research environment using Python in Ubuntu

A Brief History of Python Development

Python details: click here
Python: click here

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.