Pycharm下python使用argparse报错: error: the following arguments are required: -i/--image

Pycharm下python使用argparse报错: error: the following arguments are required: -i/–image

在学习opencv时,跑例程发现了这个错误,然后通过下面的方式解决了:

第一步 打开Run-> Edit Configurations
Pycharm下python使用argparse报错: error: the following arguments are required: -i/--image_第1张图片
第二步 加入参数
Pycharm下python使用argparse报错: error: the following arguments are required: -i/--image_第2张图片
Pycharm下python使用argparse报错: error: the following arguments are required: -i/--image_第3张图片
然后点击应用即可

我的代码中变量名:

# 设置参数
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required = True,
	help = "Path to the image to be scanned") 
args = vars(ap.parse_args())

注意添加的变量名与代码相同,然后再加入对应文件的位置
另一个例子:
代码中的变量名

# 设置参数
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True,
	help="path to input image")
ap.add_argument("-t", "--template", required=True,
	help="path to template OCR-A image")
args = vars(ap.parse_args())

配置中:
Pycharm下python使用argparse报错: error: the following arguments are required: -i/--image_第4张图片
有的时候还要注意这个图的这一页中Script path的路径地址,可能俩个py文件重名了,然后你修改了另一个py文件的参数,但一直run这个py文件。。。。

你可能感兴趣的:(opencv,python)