繁体   English   中英

在Linux中安装cx_Oracle python模块

[英]cx_Oracle python module installation in Linux

我想从Python脚本连接到Oracle数据库。 为此,我正在尝试安装cx_oracle Python模块。 我的Linux机器上未安装Oracle。

安装cx_oracle模块时,它引发错误,提示“无法找到Oracle软件安装”

有没有办法从python连接到Oracle DB,而无需在Linux框中安装Oracle。

-bash-4.1$ pip install cx_Oracle
DEPRECATION: Python 2.6 is no longer supported by the Python core team, please upgrade your Python. A future version of pip will drop support for Python 2.6
Collecting cx_Oracle
/usr/lib/python2.6/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:318: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#snimissingwarning.
  SNIMissingWarning
/usr/lib/python2.6/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
  Using cached cx_Oracle-5.3.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-PUb2Gy/cx-Oracle/setup.py", line 174, in <module>
        raise DistutilsSetupError("cannot locate an Oracle software " \
    distutils.errors.DistutilsSetupError: cannot locate an Oracle software installation

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-PUb2Gy/cx-Oracle/
/usr/lib/python2.6/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning

我绝对建议升级您的Python安装,仅是为了避免不支持的软件附带的安全问题。 您可以从https://www.python.org/downloads下载新版本。 根据您的操作系统,可能有安装Python替代版本的方法。

但是,仍然可以支持Python 2.6。 如果您使用的是Oracle Linux 6或RHEL 6,则可以从此处下载RPM。

如果需要从源代码构建,最简单的解决方案是使用cp_Oracle 6和pip,使用以下命令:

pip install cx_Oracle --upgrade --pre

cx_Oracle 6不需要安装Oracle客户端即可进行编译,但是cx_Oracle 5和更早版本则需要进行安装。

在运行时,所有版本的cx_Oracle都需要一个Oracle客户端。 安装最简单的是Oracle Instant Client,您可以在这里找到它。

sqlplus_commando可能确实是您所需要的。

您可以在代码中使用此驱动程序,如下所示:

from sqlplus_commando import SqlplusCommando

sqlplus = SqlplusCommando(主机名='localhost',数据库='测试',用户名='测试',密码='测试')结果= sqlplus.run_query(“ SELECT 42 AS response,'This is a test'AS问题from DUAL ;“)打印结果

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM