了解路由错误(Python)

2024-04-16 20:45:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试让一个程序能够调用特定文件夹中的文件。然而,由于某种原因,我不断地得到一个错误。我将发布相关代码和错误消息。你知道吗

代码:

def objmask(inimgs, inwhts, thresh1='20.0', thresh2='2.0', tfdel=True, 
            xceng=3001., yceng=3001., outdir='.', tmpdir='tmp'):
# initial detection of main galaxy with SExtractor for re-centering purposes
    if outdir!='.':
        if not os.path.exists(outdir):
            os.makedirs(outdir)

    if not os.path.exists(tmpdir):
        os.makedirs(tmpdir)
    for c in range(np.size(inimgs)):
        print 'Creating Aperture Run:', c
        subprocess.call(['sex',inimgs[c],'-c','/home/vidur/se_files/gccg.sex',
                         '-CATALOG_NAME','/home/vidur/se_files/_tmp_seobj'+str(c)+'.cat',
                         '-PARAMETERS_NAME','/home/vidur/se_files/gccg_ell.param',
                         '-FILTER_NAME','/home/vidur/se_files/gccg.conv',
                         '-STARNNW_NAME','/home/vidur/se_files/gccg.nnw',
                         '-CHECKIMAGE_TYPE','APERTURES',
                         '-VERBOSE_TYPE','QUIET',
                         '-DETECT_THRESH',thresh1,
                         '-ANALYSIS_THRESH',thresh2,
                         '-WEIGHT_IMAGE',inwhts[c]],shell=True
                         )

错误:

Creating Aperture Run: 0
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "fetch_swarp2.py", line 110, in objmask
    '-WEIGHT_IMAGE',inwhts[c]],
  File "/usr/lib/python2.7/subprocess.py", line 493, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1249, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

我的主目录中有一个名为seu files的文件夹。它的路径是/home/username/se\u文件。这是在Ubuntu上,12.04 32位。你知道吗


Tags: nameinpyhomeos错误linefiles
1条回答
网友
1楼 · 发布于 2024-04-16 20:45:22

问题是subprocess不能sex,可能是因为它不在您的路径上。你知道吗

^{}函数永远不会引发异常,因为它运行的程序返回失败;它只是将失败作为一个数字返回给您。它只会引发一个问题,它一开始就不能运行程序。你知道吗

你很容易就能看出区别:

>>> import subprocess
>>> subprocess.call(['nosuchprogram'])
[long traceback skipped]
FileNotFoundError: [Errno 2] No such file or directory: 'nosuchprogram'
>>> subprocess.call(['ls', 'nosuchfile'])
ls: nosuchfile: No such file or directory
1

第一个上升;第二个返回1。你知道吗

因此,在调用中放入sex的绝对路径,或者确保它安装正确,或者确保您的脚本在正确的环境下运行(例如,可能您只在交互式脚本中向PATH添加了/opt/sex/bin,或者您只为自己的用户添加了它,但您试图以nobody的形式运行脚本,或者…)。你知道吗

相关问题 更多 >