python installation cxOracle pit avoidance summary do not directly pip install

  • 2021-12-11 18:18:28
  • OfStack

Directory to the official website to download the corresponding version of the driver for installation. 1. Errors in the installation process: 2. The specified module cannot be found in the command line prompt. 3. The command line prompt is not a valid win32 module

Transferred from http://rookiefly.cn/detail/69

The dead little expert has nothing to do in the past two days, and reinstalled his computer. However, after reinstalling, he stepped on some pits in the configuration development environment. Here, record the pits encountered in installing cx_oracle for later viewing.

Problems with pip Installation

Command:

pip install cx_oracle

Error:

Unable to find vcvarsall.bat

I used the simplest and rudest method: Since my operating system is win10 64-bit, I installed vs2015, which unfortunately reported more errors! Since I could successfully install without pip before, I abandoned this installation method

Download the corresponding version of the driver in official website for installation

My operating system is 64-bit and Python version is 3.5. 2, so I downloaded the corresponding version from https://pypi. python. org/pypi/cx_Oracle/5. 2.1: cx_Oracle-5. 2.1-12c. win-amd64-py3.5

1. Errors during installation:

Python version 3.5 required, which was not found in the registry

Solution: I saw many kinds of solutions on the Internet, many of which are about modifying the registry. I tried this way, but I didn't succeed. Finally, I found this method and succeeded. Run the following script to add either Python3. x or 2. x to the registry:


#  Solve windows Can't be found under the platform python Registration information problem of   (Installation oracle Driver will be used) 
from winreg import *
import sys
# tweak as necessary
version = sys.version[:3]
installpath = sys.prefix
regpath = "SOFTWARE\Python\Pythoncore\{0}\".format(version)
installkey = "InstallPath"
pythonkey = "PythonPath"
pythonpath = "{0};{1}\Lib\;{2}\DLLs\".format(
    installpath, installpath, installpath)

def RegisterPy():
    try:
        reg = OpenKey(HKEY_CURRENT_USER, regpath)
    except EnvironmentError as e:
        try:
            reg = CreateKey(HKEY_CURRENT_USER, regpath)
            SetValue(reg, installkey, REG_SZ, installpath)
            SetValue(reg, pythonkey, REG_SZ, pythonpath)
            CloseKey(reg)
        except:
            print(" Unable to register!")
            return
        print("--- Python", version, "is now registered!")
        return
    if (QueryValue(reg, installkey) == installpath and
        QueryValue(reg, pythonkey) == pythonpath):
        CloseKey(reg)
        print("=== Python", version, "is already registered!")
        return
    CloseKey(reg)
    print(" Unable to register!")
    print("*** You probably have another Python installation!")
if name == "main":
    RegisterPy()

To prevent the failure of copying directly from the web page, I put it on github, which can be downloaded and run directly: register. py

2. The specified module cannot be found in the command line prompt

import cx_Oracle

ImportError: DLL load failed: The specified module cannot be found.

The solution to this problem has been said a lot on the Internet, that is, download instantclient, then unzip it and copy oci.dll to the directory of $Python_Home or $Python_Home\ Lib\ site-packages.

If you are lucky, you will succeed. If you are unlucky, you may not find the specified module. The reason is that the version of instantclient and the version of cx_Oracle are not the same. Take my installation as an example. I first downloaded instantclient11, while my cx_Oracle installed cx_Oracle-5. 2.1-12c. win-amd64-py3.5.

The correct way to do this is to download instantclient12 and cx_Oracle-5. 2.1-12c. win-amd64-py3.5.

One point to note is that cx_oracle and instantclient versions do not have to be associated with Oracle database version 1, only cx_Oracle and instantclient version 1 are required.

This problem is solved, but there are still pits waiting for you!

3. Run prompt on command line is not a valid win32 module

import cx_Oracle

DLL load failed:% 1 is not a valid Win32 application

Solution: We discussed the version problem in the previous step. In this step, it is time to talk about the number of bits in the operating system. The reason for this problem is that the number of bits in the operating system, cx_Oracle and instantclient are different. For example, I first used win10 64, cx_Oracle-5. 2.1-12c. win-amd64-py3.5 and instantclient12c (32 bits)

The correct way is to use 64-bit system for all three or 32-bit system for all three, and put oci.dll file of instantclient in the directory of $Python_Home\ Lib\ site-packages.

At this point, you should be able to solve all the problems in the installation process of cx_oracle. Good luck!

Add: Although cx_Oracle can be used in this way, the error of unable to acquire oracle ES186handle may appear when actually operating the database. The solution is to copy oci. dll, oraociei12. dll, oraocci12. dll into site-package.

Another method is to set environment variables for instantclient12c so that you don't have to copy dll files

The above is the python installation cxOracle pit avoidance summary, don't directly pip install details, more about python installation cxOracle pit avoidance information please pay attention to other related articles on this site!


Related articles: