title: Better way to run python & display python errors from PHP
body: <p>I am running a webserver for my laboratory that basically has a bunch of scripts I wrote in python for processing and analyzing tabular data.</p>
  
  <p>I have a DigitalOcean droplet with a Laravel application deployed on it. When I want to run a script, I have the user upload some data file, and then from the PHP controller run:</p>
  
  <pre><code>shell_exec(python my_script.py arg1 arg2 etc);
  </code></pre>
  
  <p>The problem is, there are differences in dependencies and libraries between my development environment and 'production' environment. As such, when I try to run the script from the webserver and there is a python error, the object returned by shell_exec is just null. When the PHP blade template tries to parse/get data from this object, I get an error like so:</p>
  
  <p><a href="https://i.stack.imgur.com/sOM6L.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sOM6L.png" alt="enter image description here"></a></p>
  
  <p>In this case, 'matchCount' is just a variable stored within a python list like this:</p>
  
  <pre><code>#Label peptides we found experimentally but do not have an in silico match for... as to predict contaminants
  output = {
      'sequence': protSeq,
      'peptides': pepList,
      'observablePeptideCount': str(len(pepList)),
      'possibleObserved': possibleObserved,
      'matchCount': matchCount,
      'coverage': matchSumAA/protSeqAALength*100,
      'massList': massList,
      'tolerances': tolerances,
  }
  output = json.dumps(output)
  </code></pre>
  
  <p>The problem is, I understand the python script failed somewhere, but the error log does not give any indication of why or where. Is there some way I can have the webpage output the python error so I can correct it in the production environment?</p>
  
  <p>Is there a better way to be doing all of this? Thank you for any help.</p>