0

I want to connect to Oracle database from Python script. For that, I am I am trying to install cx_oracle Python module. Oracle is not installed on my Linux box.

While installing cx_oracle module, it throws error saying "cannot locate an Oracle software installation"

Is there any way to connect to Oracle DB from python without installing Oracle in Linux box.

-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
Ramineni Ravi Teja
  • 3,568
  • 26
  • 37
  • 2
    This might help you: https://stackoverflow.com/questions/13234196/error-cannot-locate-an-oracle-software-installation-when-trying-to-install-cx – Darney Jul 06 '17 at 20:27
  • 1
    You need to install Oracle client software with cx_Oracle as it is needed for cx_Oracle to work. This is available in the link specified by @Darnell Martin – ivanzg Jul 06 '17 at 21:24
  • Possible duplicate of ["error: cannot locate an Oracle software installation" When trying to install cx\_Oracle](https://stackoverflow.com/questions/13234196/error-cannot-locate-an-oracle-software-installation-when-trying-to-install-cx) – Darney Jul 19 '17 at 20:13

2 Answers2

0

I would definitely recommend upgrading your Python installation, if only to avoid security issues that come with unsupported software. You can download a new version from https://www.python.org/downloads. Depending on your OS there may be ways of installing alternative versions of Python.

Python 2.6 support is still possible, however. If you are using Oracle Linux 6 or RHEL 6 you can download an RPM from here.

If you need to build from source, the simplest solution is to use cx_Oracle 6 with pip using the following command:

pip install cx_Oracle --upgrade --pre

cx_Oracle 6 doesn't require an Oracle client installation to compile but cx_Oracle 5 and earlier do.

At run-time, an Oracle client is required for all versions of cx_Oracle. The simplest to install is the Oracle Instant Client which you can find here.

Anthony Tuininga
  • 6,388
  • 2
  • 14
  • 23
0

sqlplus_commando may be what you need indeed.

You can use this driver in your code just like so:

from sqlplus_commando import SqlplusCommando

sqlplus = SqlplusCommando(hostname='localhost', database='test', username='test', password='test') result = sqlplus.run_query("SELECT 42 AS response, 'This is a test' AS question FROM DUAL;") print result