本文介绍了DPI-1050:Oracle Client库的版本为0.0,但需要版本11.2或更高版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试连接到我的工作的远程数据库,但是当我运行python脚本时,它会显示此错误。

I'm trying to connect to my work's remote DB but when I run the python script it shows this error.

我已经完成了所有操作,但错误不断出现。我尝试通过sql *连接,它可以正常工作。我下载了Oracle客户端库12.2(32位版本,因为它需要与python具有相同的体系结构),我正在使用Oracle Database 11g版本11.2.0.3,Python 3.7,并且我已经安装了Visual Studio Redistributable 2013。

I already did everything this guide says I should have as requirements but the error keeps showing. I've tried to connect through sql* and it works as it should. I downloaded oracle client libraries 12.2 (32 bits version since it needs to have the same architecture as python), I'm working with Oracle Database 11g version 11.2.0.3, Python 3.7 and I already installed Visual Studio Redistributable 2013.

这是我用来连接数据库的python脚本。显然,IP和端口与真实的IP和端口以及凭据不同。

This is the python script I'm using to connect to the DB. Obviously, the IP and port are different from the real one, as well as the credentials.

import cx_Oracle

host='196.0.0.0'
port='8080'
service_name='SID'
pwd= 'PASS'

dsn_tns = cx_Oracle.makedsn(host,port,service_name)

connection = cx_Oracle.connect('user',pwd,dsn_tns)

每当我运行它时,即使oracle客户端库文件夹已经在计算机的PATH上,也会出现错误。我是否需要从服务器端配置某些内容?谢谢您的帮助!

Whenever I run it, I get the error eventhough the oracle client libraries folder are already on the PATH of my computer. Do I have to configure something from the server side? Thanks for the help!

推荐答案

我遇到了完全相同的问题,我引用了您在此处链接的文档。我正在使用PyCharm作为IDE,并使用pycharm使用的python.exe,我发现它是32位(只需单击python.exe,然后在屏幕上打开命令提示符,然后第一行告诉它是32位还是64位)。

I had the exact same issue and I referred to the document you linked here. I am using PyCharm as the IDE and using the python.exe which pycharm uses, I found it is 32 bit (just click the python.exe and the command prompt like screen opens and first line tells if it is 32bit or 64 bit).

然后使用下面的链接下载了Oracle Instant Client。

Then using the below link, I downloaded the Oracle Instant Client.

我选择了32位和12.2版本(在撰写本文时,最新版本为v18.x)。这个32位必须匹配您的python版本(在我的情况下也是32位)。

I chose the 32 bit and 12.2 version (latest was v18.x at the time of writing this). This 32bit has to match your python version (which was also 32 bit in my case).

然后我提取了即时客户端的zip文件,放在C:C中\oracle文件夹(放在哪里都无所谓),我的目录结构是..

Then I extracted the zip file of instant client, put it in C:\oracle folder (doesn't matter where you put) and the my directory structure was..

现在,我将此位置作为Windows计算机的 Path系统环境变量中的第一个位置。

Now I put this location as first location in my "Path" system environment variable of Windows machine.

完成所有这些操作后,我重新启动了计算机(不需要)并使用了pycharm并像这样进行连接...

After doing all this, I restarted machine (not needed) and used pycharm and connected like this...

import cx_Oracle as cxo
conn = cxo.connect("user_id", "password", "host_name:port_no/sid")
print(conn.version)
cur = conn.cursor()
cur.execute('SELECT \'X\' FROM DUAL')
for result in cur:
    print(result[0])
cur.close()
conn.close()

这篇关于DPI-1050:Oracle Client库的版本为0.0,但需要版本11.2或更高版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 15:01