我想将我的django项目从开发服务器移到生产服务器。我用一个(BIG)例外解决了几乎所有的问题。当我在终端中运行以下代码(使用python manage.py shell
)时,它工作正常,但是通过我的apache服务器(使用mod_wsgi)运行时运行不正常。'找不到命令'在apache中使用子进程时出错'
我的代码:
...
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()
...
当我在看我的日志文件
ncbi_error_log.log
我通过终端我得到运行后(作为一个例子)
:
2011-12-17 12:30:54.771292:
所以没有错误。然而,当我通过我的Apache服务器上运行我得到:
2011-12-17 12:28:59.755323: /bin/sh: blastn: command not found
我已经尝试了解决这个问题的广泛搜索,但无法找到任何东西,让修复 - 尽管我希望我昭然若揭失去了一些东西很明显,所以我可以很快地对此进行分类
附加信息:
OS X雪豹
Python版本2.7.2是
的Django 1.3
PATH包含BLASTN目录
如果您想要查看任何其他代码,请告诉我。
解决:
通过改变
process = subprocess.Popen(str(blastn_cline),shell=True,stdout = subprocess.PIPE, stderr = subprocess.PIPE)
到
process = subprocess.Popen('/Users/basehunt/BLAST/ncbi-blast-2.2.25+/bin/'+str(blastn_cline),shell=True,stdout = subprocess.PIPE, stderr = subprocess.PIPE)
,以绝对的指向功能。非常感谢。
嗨格雷厄姆,非常感谢。正如我在编辑中提到的那样,我需要用''''而不是'/'来指定我的路径。不知道这是为什么。另外,你对这个问题删除的有关'/ bin/sh'搞乱的评论是如此的正确......这样做真的和我的服务器搞砸了,我不得不做很多救援。另外,在modwsgi上做的很棒!再次感谢。 – rjralgar 2011-12-19 01:03:07
你不应该需要双斜杠,所以不知道那里发生了什么,除非你第一次更改代码时没有重新加载代码。甚至无法想象为什么你会想到首先尝试双斜杠。关于源代码重新加载的问题,可能是http://code.google。com/p/modwsgi/wiki/ReloadingSourceCode – 2011-12-19 01:37:56
完全正确 - 我没有正确地重新加载我的源代码,完全愚蠢。没想到我从一开始就没有写过斜线,但git告诉我我做过了(为什么我会这样做,我不知道 - 认为我的大脑已经从这个'/ bin/sh'问题中被炒掉了) 。无论如何,再次感谢。 – rjralgar 2011-12-19 01:45:52