Linux中的cx_Oracle python模块安装

时间:2017-07-06 19:28:16

标签: python linux oracle

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

安装cx_oracle模块时,会抛出错误,说“无法找到Oracle软件安装”

有没有办法从python连接到Oracle数据库而无需在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

2 个答案:

答案 0 :(得分:0)

如果只是为了避免不受支持的软件带来的安全问题,我肯定会建议升级您的Python安装。您可以从https://www.python.org/downloads下载新版本。根据您的操作系统,可能有多种方法可以安装Python的替代版本。

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

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

pip install cx_Oracle --upgrade --pre

cx_Oracle 6不需要安装Oracle客户端,但cx_Oracle 5及更早版本可以安装。

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

答案 1 :(得分:0)

sqlplus_commando可能确实是你需要的。

您可以在代码中使用此驱动程序:

from sqlplus_commando import SqlplusCommando

sqlplus = SqlplusCommando(hostname =&#39; localhost&#39;,database =&#39; test&#39;,                           username =&#39; test&#39;,password =&#39; test&#39;) result = sqlplus.run_query(&#34; SELECT 42 AS response,&#39;这是一个测试&#39; AS问题来自DUAL;&#34;) 打印结果