错误:参数-s / - source是必需的

时间:2018-06-19 04:41:45

标签: python machine-learning computer-vision object-identity

我从Github复制了这段代码,但它对我不起作用。

示例代码:

init: function() {
        var me = this
        var me = this.view
    },

和此输出

ap = argparse.ArgumentParser()
ap.add_argument("-s", "--source", required=True, help="Path to the source of shapes")
ap.add_argument("-t", "--target", required=True, help="Path to the target image")
args = vars(ap.parse_args())

请帮帮我。感谢

2 个答案:

答案 0 :(得分:0)

问题标题中的错误消息非常明显。

ap.add_argument("-s", "--source", required=True, help="Path to the source of shapes")

您将required=True放在此参数上。这意味着它是必需的。因此,如果您尝试运行此脚本,并且未在命令行中放置--source(或-s)参数,则会出现错误。

如果您不想要它,请不要放required=True

另一方面,您在问题末尾显示的输出不可能来自此代码。您的-src规范中没有-trgargparse参数。也许你正在运行一个完全不同的程序?如果是这样,我们就可以通过查看该程序的代码来调试该程序。

答案 1 :(得分:-1)

我认为你没有把参数-s放在python excute命令中。 假设python代码保存在名为detect_leaf.py的文件中 你必须把参数-s放在下面

python detect_leaf.py -s SOURCE -t TARGET

并且有两种方法可以访问参数值,如下面的

import argparse
ap = argparse.ArgumentParser(description='Process some integers.')
ap.add_argument("-s", "--source", required=True,  help="Path to the source of shapes")
ap.add_argument("-t", "--target", required=True,  help="Path to the target image")

#It's Dictionary
vars_args = vars(ap.parse_args())

print(vars_args['source'])
print(vars_args['target'])

#It's NameSpace object
parsed_args = ap.parse_args()

print(parsed_args.source)
print(parsed_args.target)
相关问题