簡體   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