2015-08-28 74 views
0

我想運行一個python腳本。腳本的第一個步驟來運行正常,但在某些時候我有這樣的消息:Python錯誤沒有這樣的文件或目錄,但有文件

Traceback (most recent call last): 
    File "/home/chodar/Descargas/00.Comprimidos/REPET_linux-x64-2.2/bin/LaunchTRF.py", line 154, in <module> 
    iLaunchTRF.run()   
    File "/home/chodar/Descargas/00.Comprimidos/REPET_linux-x64-2.2/bin/LaunchTRF.py", line 143, in run 
    self._launchTRF() 
    File "/home/chodar/Descargas/00.Comprimidos/REPET_linux-x64-2.2/bin/LaunchTRF.py", line 101, in _launchTRF 
    process = subprocess.Popen(cmd.split(' '), stdout=subprocess.PIPE, stderr=subprocess.PIPE) 
    File "/usr/lib/python2.7/subprocess.py", line 710, in __init__ 
    errread, errwrite) 
    File "/usr/lib/python2.7/subprocess.py", line 1327, in _execute_child 
    raise child_exception 
OSError: [Errno 2] No such file or directory 
2015-08-28 12:38:05 - DetectTEFeatures - ERROR - ERROR when launching 'LaunchTRF.py -i TEs.60bp.fa -o TEs.60bp.fa.SSR.set -m 15 -c -v 0 > launchTRF.log' 
Traceback (most recent call last): 
    File "PASTEClassifier.py", line 199, in <module> 
    iLaunch.run()   
    File "PASTEClassifier.py", line 165, in run 
    iDF.run() 
    File "/home/chodar/Descargas/00.Comprimidos/REPET_linux-x64-2.2/commons/tools/DetectTEFeatures.py", line 185, in run 
    self._detectFeatures() 
    File "/home/chodar/Descargas/00.Comprimidos/REPET_linux-x64-2.2/commons/tools/DetectTEFeatures.py", line 204, in _detectFeatures 
    self._detectTRF() 
    File "/home/chodar/Descargas/00.Comprimidos/REPET_linux-x64-2.2/commons/tools/DetectTEFeatures.py", line 267, in _detectTRF 
    self._logAndRaise("ERROR when launching '%s'" % cmd) 
    File "/home/chodar/Descargas/00.Comprimidos/REPET_linux-x64-2.2/commons/tools/DetectTEFeatures.py", line 176, in _logAndRaise 
    raise Exception(errorMsg) 
Exception: ERROR when launching 'LaunchTRF.py -i TEs.60bp.fa -o TEs.60bp.fa.SSR.set -m 15 -c -v 0 > launchTRF.log' 

我看了一些其他職位有這種類型的錯誤,並基於這些,我看着如果LaunchTRF.py存在,它在那兒。實際上,當我僅運行LaunchTRF.py而沒有任何選項時,我可以看到選項列表和幫助。我在想,丟失的文件是TEs.60bp.fa,但它也存在。

下面是在情況下,線98至103從LaunchTRF.py可能有助於:

def _launchTRF(self): 
     cmd = "trf %s 2 3 5 80 10 20 %d -h -d" % (self.inFileName, self.maxPeriod) 
     self._log.debug("Running : %s" % cmd) 
     process = subprocess.Popen(cmd.split(' '), stdout=subprocess.PIPE, stderr=subprocess.PIPE) 
     output = process.communicate() 
     self._log.debug("Output:\n%s" % output[0]) 

任何幫助是受歡迎的。

+0

你可以做一個打印(self.inFileName) 。確保該文件具有完整的路徑名不只是blah.txt – FirebladeDan

回答

0
print(self.inFileName) 

應該等於

"C:\blah\something\test.txt" 

,如果它不只是在命令前加上名字

fullFile = "C:\blah\hooray\"+self.inFileName 

cmd = "trf %s 2 3 5 80 10 20 %d -h -d" % (fullFile, self.maxPeriod) 
0

這似乎與你的工作目錄中的問題,也許是父腳本正在更改它,或者您正在從另一個目錄執行父腳本。

,你可以做些什麼來解決這個問題是通過傳遞一個額外的參數去工作目錄改變popen方法:

subprocess.Popen('./LaunchTRF.py ...', cwd='/path/to/')

希望它可以幫助

+0

謝謝@Filipe我會嘗試這個解決方案,我讓你知道 – christian

+0

我修改subprocess.Popen process = subprocess.Popen(cmd.split(''), stdout = subprocess.PIPE,stderr = subprocess.PIPE,cwd =「/ home/chodar/Descargas/00.Comprimidos/REPET_linux-x64-2.2/bin /」)。沒有工作,但我不是,如果我做得很好... – christian

+0

錯誤信息是否保持不變? – Filipe

相關問題