title: Running Python script from PHP / MAMP
body: <p>I have some python scripts that I need to run from PHP and then show the result in a browser.</p>
  
  <p>I'm having some problem running them using MAMP.</p>
  
  <p>I have the following Python script that runs fine from the command line (obviously):</p>
  
  <pre><code>#!/usr/bin/env python
  
  for friend in ['Miguel', 'Nelson']:
      print friend
  </code></pre>
  
  <p>Then I have a PHP script that tries to execute the previous script:</p>
  
  <pre><code>$output = array();
  exec("python &lt;absolutePath&gt;/script.py", $output);
  echo var_dump($output);
  </code></pre>
  
  <p>This script works when I run it from the command line like this:</p>
  
  <pre><code>php script.php
  </code></pre>
  
  <p>And shows the expected result:</p>
  
  <pre><code>array(2) {
      [0]=&gt;
      string(6) "Miguel"
      [1]=&gt;
      string(6) "Nelson"
  }
  </code></pre>
  
  <p>But when I try to run it through the browser (routing with Slim framework) it doesn't work. The result is an empty array.</p>
  
  <p>I've already changed the permissions of both the parent directory and the python script but it still doesn't work. </p>
  
  <p>Any idea of what the problem might be?</p>
  
  <p><strong>Update</strong></p>
  
  <p>I've also tried with the 'exec' command but the result was the same. But it only fails when it tries to execute the python scripts, if I request a simple 'ls' command it works and shows the result of it.</p>