Directory Introduction Body 1 Cannot import name ‘SourceDistribution’ 2 Dpi-1047: Cannot locate a 64-bit Oracle Client library3 make sure you have the 32 bits oracle client installed4 ORA-12154: I thought this would be enough to write an article about the offline installation of third-party libraries in Python.

preface

I thought this would be enough to write an article about the offline installation of third-party libraries in Python. There are many ways to connect to Oracle using Python, and cX-Oracle is used in this article. In addition, this article is completely in the case of not connected to the Internet operation, can connect to the Internet is not so troublesome.

The body of the

1 cannot import name ‘SourceDistribution’

Cx-oracle has been installed on Linux, but it is not available on Windows. The cX-Oracle has been installed on Linux. I first use a laptop that can connect to the Internet at pypi.org/project/cx-… Error: PIP install ImportError: cannot import name ‘SourceDistribution’

pip install d:\xx\xx.whl
Copy the code

I looked it up and said it was the PIP version and needed an upgrade. The first problem is that using this method to upgrade PIP through the offline installation of the problem is definitely not possible. How to do? I then used the third method written in Python’s offline installation third-party library, the source installation upgrade PIP, and then cX-Oracle.

2 DPI-1047: Cannot locate a 64-bit Oracle Client library

cx_Oracle.DatabaseError: DPI-1047: Cannot locate a 64-bit Oracle Client library: D:\xx\oci. DLL is not the correct architecture D:\xx\oci. DLL Oracle Client also need to be 64, small problems, go to the website to download: www.oracle.com/database/te… However, there is a problem again. You need to register your Oracle account to download oracle. After registration, you can log in to the Oracle official website.

After a long search, I finally found a 64-bit one on CSDN, downloaded it and uploaded it to a machine without Internet access. However, there is a problem. See you next.

3 make sure you have the 32 bits oracle client installed

PLSQL Developer does not support oracle 64 – bit client connection. Luckily, I was smart enough to remember that I could set the OCI library in PLSQL, so I changed it to 32 bits, and environment variables to 64 bits, so it co-existed perfectly.

4 ORA-12154: TNS

cx_Oracle.DatabaseError: ORA-12154: TNS

On Linux, ora_addr is written as “IP :port/orcl”. On Windows, ora_addr is written as the instance name, which is specified in tnsnames.ora.

Example:

import cx_Oracle

ora_name = ""
ora_pasw = ""



ora_addr = "xx-log"


def ora_query(sql_log):
    print(sql_log)

    conn = cx_Oracle.connect(
        '{ora_name}/{ora_pasw}@{ora_addr}'.format(ora_name=ora_name, ora_pasw=ora_pasw, ora_addr=ora_addr))
    curs = conn.cursor()
    res = curs.execute(sql_log)
    row = res.fetchone()
    curs.close()
    conn.close()
    return row


if __name__ == '__main__':
    res1 = ora_query("select * from ETL_JOB_STATUS t where t.etl_job='audit_fraud_outbound_d_s'")
    print res1
Copy the code

I have many years of big data and machine learning development experience, and I am willing to summarize and share, if there is infringement or writing wrong place can be private message to me, you can also ask me questions, free~