cx_Oracle for Python requires certain Environmental Variables to be set in place to import and work correctly. Rather than trying to wrap my application in a bash script, which I've done in the past, I'm trying to setup the variables using only Python.
Below is what I have in place so far.
# Check if OS environment variables are setup.
if 'ORACLE_HOME' not in os.environ.keys():
os.environ['ORACLE_HOME'] = '/usr/lib/oracle/12.1/client64'
if 'LD_LIBRARY_PATH' not in os.environ.keys():
os.environ['LD_LIBRARY_PATH'] = os.environ['ORACLE_HOME'] + '/lib'
if '/usr/lib/oracle' not in os.environ['PATH']:
os.environ['PATH'] = os.environ['ORACLE_HOME'] + '/bin:' + os.environ['PATH']
# Initialize Environmental Variables for cx_Oracle
It is likely this question has been already answered on this site: How to change environment variables in python? I am quoting the accepted answer:
You can set them that way, however $LD_LIBRARY_PATH is read by the loader which has already run before that therefore you must set that one externally beforehand.