2

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 python manage.py shell) it works fine, however running through my apache server (with mod_wsgi) it does not run fine.

My 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()
    ...

when I look at my log file ncbi_error_log.log after I run through terminal I get (as an example):

2011-12-17 12:30:54.771292:

so no error. However, when I run through my apache server I get:

2011-12-17 12:28:59.755323: /bin/sh: blastn: command not found

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.

Additional info:

  • OS X Snow Leopard

  • python version is 2.7.2

  • django 1.3

  • PATH contains the directory with blastn

If there is any additional code you want to see, let me know.

SOLVED:

by changing

process = subprocess.Popen(str(blastn_cline),shell=True,stdout = subprocess.PIPE, stderr = subprocess.PIPE)

to

process = subprocess.Popen('/Users/basehunt/BLAST/ncbi-blast-2.2.25+/bin/'+str(blastn_cline),shell=True,stdout = subprocess.PIPE, stderr = subprocess.PIPE)

in order to point absolutely to the function. Many thanks.

1 Answer 1

4

When running under Apache/mod_wsgi you MUST use a full path name to program being run, or any files being access for that matter. This is because your user PATH is not inherited or used by Apache. The current working directory of the process could also be anything, so can't rely on relative paths either.

So, instead of just 'blastn', use '/some/path/blastn', replacing '/some/path/' with the full path to where the program is located.

Sign up to request clarification or add additional context in comments.

3 Comments

Hi Graham, many thanks for this. As I mention in in my edit to show the solution I needed to prepend my path with // not just /. Not sure why this is. In addition your comment on the deleted answer to this question regarding messing with /bin/sh was so right...doing that really screwed with my server and I had to do a LOT of saves to rescue. Also, great work on modwsgi! Thanks again.
You should not have needed the double slash, so not sure what is going on there except perhaps when you made change first time the code hadn't been reloaded. Can't even imagine why you would think to try double slash in the first place. On issues of source code reloading, maybe read code.google.com/p/modwsgi/wiki/ReloadingSourceCode
Completely correct - I had not reloaded my source code properly, complete stupidity. Didn't think I had ever written it without a slash at the start, but git tells me I did (why I would have done that I don't know - think my brain has fried from this /bin/sh issue). Anyway, thanks again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.