Category:python
Article From:https://www.cnblogs.com/lp19910807/p/9121546.html

A:

python3.6.3Download address: WGet https://www.Python.org/ftp/python/3.6.3/Python-3.6.3.tgz

After decompression, go to the decompressed directory, install directly:

Modify the temporary language first:

export LANG=zh_CN.UTF-8

Installation:

./configure –prefix=/usr/local/python3.6.3 –with-ssl

make && make install

Python: with a backup system

mv /usr/bin/python /usr/bin/pythonbak

Create a new Python soft link:

ln -s /usr/local/python3.6.3/bin/python3.6 /usr/bin/python

Modify the yum configuration file to prevent Yum from being unavailable

Change the head of the file to /usr/bin/python! /usr/bin/python2.6. save and exit.

 

B:

Install cx_oracle (using PIP3 installation)

The cx_Oralce module that installs Python needs to rely on Oracle Instant Client:

Download instantclient_12_2 link: https://pan.baidu.com/s/1xOyTDDK9ePng52m9VLvj8A password: mdln

Alternate address: https://support.cloudcc.com/install/instantclient_12_2.zip

mkdir -p /u01/install && mv /tmp/instantclient_12_2 /u01/install (/u01/installThis path is optional, not necessarily the same as mine.

Modify the environment variable:

vim /etc/profile.d/oracle.sh

export ORACLE_HOME=/u01/install/instantclient_12_2
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME

The environment variable takes effect source /etc/profile.d/oracle.sh

See:

a:Installation of direct production environment

cd /usr/local/python3.6.3/bin/

./pip3 install cx_oracle

 

b:Create a virtual environment for python3 (isolation from Python installed under the system)

 python3 -m venv /opt/py3
source /opt/py3/bin/activate 
Install cx_oracle
pip3 install cx_oracle

 

What problems do you encounter in the chart, please do Baidu yourself. It is not very difficult. Yum is installed with some dependencies.

 A template is attached.

 import cx_Oracle

class Oracle_Helper(object):

    def __init__(self):
        self.db_url = “1.1.1.1/name”
        self.db_username = “user”
        self.db_userpassword = “pwd”

    def open(self):
        self.conn = cx_Oracle.connect(self.db_username, self.db_userpassword, self.db_url)
        self.c = self.conn.cursor()

    def run(self, sql):
        sql = sql
        x = self.c.execute(sql)
        data = x.fetchall()
        return data

def close(self):
        self.c.close()
        self.conn.close()

    def __enter__(self):
        self.open()
        return self

    def __exit__(self, exc_type, exc_val, exc_tb):
        self.close() 

Leave a Reply

Your email address will not be published. Required fields are marked *