如何修复“错误:需要以下参数:-i/--image"; [英] How to fix "error: the following arguments are required: -i/--image"
本文介绍了如何修复“错误:需要以下参数:-i/--image";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在看别人的代码并关注python代码;
I was looking at someone else's code and following python code;
import argparse
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True, help="path to the input image")
args = vars(ap.parse_args())
在最后一行给出以下错误;
gives the following error on the last line;
usage: sample.py [-h] -i IMAGE
sample.py: error: the following arguments are required: -i/--image
我该如何解决这个问题?到目前为止,我所尝试的一切似乎都没有帮助.
How can I fix this problem? Nothing I have tried so far seems to help.
推荐答案
运行sample.py
时,需要指定-i
/--图像
参数:
When running sample.py
, you need to specify the -i
/--image
argument:
python sample.py --image image/cat.png
如果您希望 image
参数是可选的,请删除 required=True
:
If you want the image
argument to be optional, remove required=True
:
ap.add_argument("-i", "--image", help="path to the input image")
这篇关于如何修复“错误:需要以下参数:-i/--image";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文