如何解决“错误:需要以下参数:-i/-image"; [英] How to fix "error: the following arguments are required: -i/--image"

查看:122
本文介绍了如何解决“错误:需要以下参数:-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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆