title: Setup cx_Oracle Environmental Variables with Python
body: <p>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.</p>
  
  <p>Below is what I have in place so far.</p>
  
  <pre><code># 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']
  
  import cx_Oracle
  </code></pre>
  
  <p>Unfortunately I'm still receiving the exception from cx_Oracle that basically means the variables are not setup properly.</p>
  
  <p>I've also attempted using <code>subprocess.Popen()</code> and <code>subprocess.call()</code> to call the exports directly, but I'm not sure if they are just not working or I'm not understanding those functions correctly.</p>
  
  <p>What is the best way to setup these variables so that I can import cx_Oracle using just Python 3.</p>
  
  <p>Edit, Below is what I typically add to my bash wrappers:</p>
  
  <pre><code>#!/bin/sh
  
  # Initialize Environmental Variables for cx_Oracle
  export ORACLE_HOME=/usr/lib/oracle/12.1/client64
  export LD_LIBRARY_PATH=$ORACLE_HOME/lib
  export PATH=$ORACLE_HOME/bin:$PATH
  
  (Python Script)
  </code></pre>