Forum Stats

  • 3,781,246 Users
  • 2,254,495 Discussions


Is the "Oracle Database for Python Developers Quickstart" in need of updating ?

I'm a new student user trying to setup a python scripted Oracle database so I apologize if my formatting or tech-speak is wrong. On the "Oracle Database for Python Developers, Part 1: cx_oracle quick start page.

They say that I should run the file but there is some formatting issues and I'm not sure what or how to fix it.

To start it adds expo infant of the import statement which causes an issue in python so I commented it out, then the bottom line starts with "rt" but I'm not aware of what that is.

# expo
import cx_Oracle
   conn = cx_Oracle.connect("hr", "oracle", "dbhostname/orcl")
   sql="""SELECT d.* FROM departments d, locations l WHERE = :city AND d.location_id = l.location_id"""
   column_length=[5, 22, 6, 5]
   cursor = conn.cursor()
   for row in cursor.execute(sql, city = 'Seattle'):
      for i in range (len(row)):
         print(str(row[i]).ljust(column_length[i]), end='')
except cx_Oracle.DatabaseError as exc:
   err, = exc.args
   print("Oracle-Error-Code:", err.code)
   print("Oracle-Error-Message:", err.message)
   rt LD_LIBRARY_PATH=/usr/lib/oracle/12.2/client64/lib:$LD_LIBRARY_PATH

Can anybody link me to a python script that works for python 3.8 or at least python 3. I'm getting better at learning python but now that I'm adding oracle database to it things get complicated quick.


  • user9540031
    user9540031 Member Posts: 144 Silver Badge

    Well... Looks like the "expo" bit has something to do with that "rt" thing down below 😉, yielding:

    export LD_LIBRARY_PATH=/usr/lib/oracle/12.2/client64/lib:$LD_LIBRARY_PATH

    which is obviously not Python, but totally Unix shell, and is arguably a prerequisite to have the LD_LIBRARY_PATH environment variable properly set up in order to have the OCI (Oracle Client Interface) library in the search path for shared libraries.

    My two cents... Hope this helps! (& Best of luck!)

  • @user9540031 So what you are saying is that I run the "export LD_LIBRARY..." from bash/linux to setup my PATH to accept oracle ?

  • user9540031
    user9540031 Member Posts: 144 Silver Badge


    LD_LIBRARY_PATH defines the search path for shared libraries—for details, see: man Don't confuse it with PATH, which defines the search path for commands; both variables work the same way, but each serves its own purpose.

    AFAIK, the cx_Oracle Python module depends on the OCI library, therefore that library must be found in the search path.

    Don't forget to replace /usr/lib/oracle/12.2/client64/lib with the relevant path for your system: the Oracle client may be installed in a different place.

    Perhaps everything is already configured on your system: can you run sqlplus?

    $ sqlplus /nolog
    SQL*Plus: Release - Production on Fri Dec 18 10:55:27 2020
    Copyright (c) 1982, 2019, Oracle.  All rights reserved.
    SQL> exit
    • If yes, you don't have anything more to do: the Oracle client is installed, and environment variables are properly set up.

    (And if you run the ldd command on the sqlplus binary you'll see that all dependencies are satisfied:

    $ which sqlplus
    $ ldd $(which sqlplus)
   =>  (0x00007ffce2128000)
   => /u01/app/oracle/product/19/lib/ (0x00007f0e1061c000)
   => /u01/app/oracle/product/19/lib/ (0x00007f0e0c5f0000)
   => /u01/app/oracle/product/19/lib/ (0x00007f0e0c050000)
   => /lib64/ (0x00007f0e0a5db000)
            /lib64/ (0x00007f0e10908000)
 and are the main components in the OCI library.)

    • If not: you need to find where the Oracle client is installed on your system, and set LD_LIBRARY_PATH accordingly (and export it so it is defined in child processes too).

    In case the Oracle client is not installed, or you can't find it, you may just download it from Oracle (here: Most likely you'll need the Basic Package, SQL*Plus Package, and Tools Package: the OCI library comes with the Basic Package, but sooner or later you might need SQL*Plus / SQL*Loader to work with your database, so they're probably a useful addition.

    Remark: on the download page, you may see the following mention:

    Version (Requires glibc 2.14)

    The release 2.14 of glibc is fairly old, so that requirement will be met on most systems, but it's worth checking anyway:

    $ rpm -qa | grep glibc

    So it seems I have glibc release 2.17 on this box, which is fine 😊