title: 'command not found' error when using subprocess in apache
body: <p>I am trying to move my django project from a development server to a production server. I have ironed out almost everything with one (BIG) exception. When I run the following code in the terminal (using <code>python manage.py shell</code>) it works fine, however running through my apache server (with mod_wsgi) it does not run fine.</p>
  
  <p>My code:</p>
  
  <pre><code>    ...
      blastn_cline = NcbiblastnCommandline(query=filepath, db=db, evalue=0.1, outfmt=5, out=out, task="blastn-short", dust="no")
      process = subprocess.Popen(str(blastn_cline),shell=True,stdout = subprocess.PIPE, stderr = subprocess.PIPE)
      proc_out, proc_err = process.communicate()
      err_log = open('/Users/basehunt/logs/ncbi_error_log.log', 'a+')
      err_log.write("\n"+str(datetime.datetime.now())+": "+str(proc_err))
      err_log.close()
      ...
  </code></pre>
  
  <p>when I look at my log file <code>ncbi_error_log.log</code> after I run through terminal I get (as an example):</p>
  
  <pre><code>2011-12-17 12:30:54.771292:
  </code></pre>
  
  <p>so no error. However, when I run through my apache server I get:</p>
  
  <pre><code>2011-12-17 12:28:59.755323: /bin/sh: blastn: command not found
  </code></pre>
  
  <p>I have tried to search extensively for a solution to this problem but can't find anything that gives a fix - though I hope I am missing something glaringly obvious so I can quickly sort this out.</p>
  
  <p>Additional info:</p>
  
  <ul>
  <li><p>OS X Snow Leopard</p></li>
  <li><p>python version is 2.7.2</p></li>
  <li><p>django 1.3</p></li>
  <li><p>PATH contains the directory with blastn</p></li>
  </ul>
  
  <p>If there is any additional code you want to see, let me know.</p>
  
  <p>SOLVED:</p>
  
  <p>by changing</p>
  
  <pre><code>process = subprocess.Popen(str(blastn_cline),shell=True,stdout = subprocess.PIPE, stderr = subprocess.PIPE)
  </code></pre>
  
  <p>to</p>
  
  <pre><code>process = subprocess.Popen('/Users/basehunt/BLAST/ncbi-blast-2.2.25+/bin/'+str(blastn_cline),shell=True,stdout = subprocess.PIPE, stderr = subprocess.PIPE)
  </code></pre>
  
  <p>in order to point absolutely to the function. Many thanks.</p>