Python错误没有这样的文件或目录,但文件在那里

时间:2015-08-28 15:57:33

标签: 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,但它也在那里。

以下是LaunchTRF.py中98到103行,以防可能有所帮助:

 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])

欢迎任何帮助。

2 个答案:

答案 0 :(得分: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)

答案 1 :(得分:0)

这似乎与您的工作目录有关,也许父脚本正在更改它,或者您正在从另一个目录执行父脚本。

你可以做些什么来解决这个问题,就是通过将一个额外的参数传递给popen来改变工作目录:

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

希望有所帮助