Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Python what do you need to pay attention to when installing cxOracle

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces the python installation of cxOracle need to pay attention to what, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to know about it.

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 and unfortunately reported more errors! I abandoned this installation method because I could install it successfully without using pip installation before.

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

My operating system is 64-bit, and the Python version is 3.5.2, so I went to https://pypi.python.org/pypi/cx_Oracle/5.2.1 to download the corresponding version: 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: there are many solutions on the Internet, many of which are about modifying the registry. I tried this way, but I didn't succeed. I finally found this method and succeeded. Run the following script, either Python3.x or 2.x, to add to the registry:

# solve the problem that the registration information of python cannot be found under the windows platform (used to install the oracle driver) from winreg import * import sys# tweak as necessaryversion = sys.version [: 3] installpath = sys.prefixregpath = "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 ()

In order 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

two。 The specified module could not be found when running the prompt on the command line

Import cx_Oracle

ImportError: DLL load failed: the specified module was not found.

The solution to this problem is to download instantclient, unzip and copy the oci.dll to the $Python_Home or $Python_Home\ Lib\ site-packages directory.

If you are lucky, you will be successful. if you are unlucky, you may not be able to find the specified module, because the version of instantclient is inconsistent with the version of cx_Oracle. Take my installation as an example, I downloaded instantclient11 first, while my cx_Oracle is installed with cx_Oracle-5.2.1-12c.win-amd64-py3.5, one is 11, the other is 12c, so there is still the problem of not finding the specified module.

The right thing to do is to download instantclient12 and cx_Oracle-5.2.1-12c.win-amd64-py3.5.

Note that the version of cx_oracle and instantclient does not have to be the same as the version of the Oracle database, just the same version of cx_Oracle and instantclient.

So the problem is solved, but there are still holes waiting for you!

3. The prompt running on the command line is not a valid win32 module

Import cx_Oracle

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

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

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

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

Add: although this is possible to use cx_Oracle, but the actual operation of the database may occur unable to acquire oracle environment handle this error, the solution is to copy oci.dll, oraociei12.dll, oraocci12.dll to site-package.

Another way is to set the environment variable for instantclient12c so that you don't have to copy the dll file

Thank you for reading this article carefully. I hope the article "what do you need to pay attention to when installing python cxOracle" shared by the editor will be helpful to you? at the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report