【问题标题】:not able to work with cx-oracle无法使用 cx-oracle
【发布时间】:2018-12-10 02:01:33
【问题描述】:

我是 python 和 oracle 的新手,我已经编写了连接到 oracle 数据库 11g 的代码,但是它给出了一个错误:

import cx_Oracle
    con=cx_Oracle.connect('sys/Satyam123@localhost/xe')
    con.close(

)


It gives the following error in pycharm:

C:\Users\DELL\venv\module2\Scripts\python.exe C:/Users/DELL/Desktop/PYTHON/module2/check.py Traceback(最近 最后调用):文件“C:/Users/DELL/Desktop/PYTHON/module2/check.py”, 第 2 行,在 con=cx_Oracle.connect('sys/Satyam123@localhost/xe') cx_Oracle.DatabaseError: DPI-1047: 32-bit Oracle Client library cannot 被加载:“找不到指定的模块”。看 https://oracle.github.io/odpi/doc/installation.html#windows求帮助

【问题讨论】:

    标签: python oracle pycharm cx-oracle


    【解决方案1】:

    请下载并安装 Oracle 客户端。 (Oracle 客户端有多个版本,但即时可用):

    http://download.oracle.com/otn/nt/instantclient/122010/instantclient-basic-nt-12.2.0.1.0.zip

    安装后,cx_Oracle python 模块将查找 Oracle 库 (OCI) 并加载它们。

    【讨论】:

    • 我已经安装了oracle database 11g,还要安装oracle客户端,为什么?当我已经有了oracle数据库11g时,两者有什么区别
    • 只要安装了Oracle数据库就不需要Oracle客户端。确保可以在系统路径 %PATH% 中找到“oci.dll”:C:\>type oci.dll(应该列出)
    【解决方案2】:

    我有同样的问题。请点击链接https://oracle.github.io/odpi/doc/installation.html 并根据您的系统版本安装 Oracle Instant Client 64 位或 32 位。一旦安装了这个,python 将自动能够找到 Oracle 客户端库,并且您可以成功连接到数据库。

    【讨论】:

      【解决方案3】:

      似乎存在与 PATH 相关的问题。您可以尝试使用 IDE 终端安装软件包。在您的情况下,请尝试使用 pycharm 终端安装软件包。

      然后尝试执行以下脚本:

      import cx_Oracle
      import db_config
      user="test"
      pw="test"
      dsn="localhost:port/TEST" #here TEST is service id
      
      con = cx_Oracle.connect(user, pw, dsn)
      
      cur = con.cursor()
      cur.execute("select * from test_table")
      res = cur.fetchall()
      for row in res:
          print(row)
      

      还有问题可以参考:

      [https://oracle.github.io/python-cx_Oracle/samples/tutorial/Python-and-Oracle-Database-Scripting-for-the-Future.html]

      【讨论】:

      • 我认为这个问题更有可能是 32 位与 64 位的问题。 Python 和 Oracle 客户端库需要是相同的架构。在这个问题中,Python 是 32 位的(如寻找 32 位库的消息所示),XE 很有可能是 64 位的。解决方案是安装 64 位 Python,或安装 32 位 Instant Client。
      猜你喜欢
      • 2012-12-23
      • 2016-05-15
      • 1970-01-01
      • 2019-04-17
      • 1970-01-01
      • 2023-03-21
      • 2016-03-02
      • 2021-11-26
      • 2019-11-07
      相关资源
      最近更新 更多