python - 为什么在 python 中执行 argparse 时出现错误

标签 python

我无法解析 python 中的参数以使用 OpenCv、python 和 dlib 检测眨眼。

ap = argparse.ArgumentParser()
ap.add_argument("-p", "--shape-predictor", required=True,
        help="path to facial landmark predictor")
ap.add_argument("-v", "--video", type=str, default="",
    help="path to input video file")
args = vars(ap.parse_args())
ap.add_argument("-p", "--shape-predictor", required=True)

_StoreAction(option_strings=['-p', '--shape-predictor'], 
dest='shape_predictor', nargs=None, const=None, default=None, type=None, 
choices=None, help=None, metavar=None)
ap.add_argument("-v", "--video", type=str, default="")
_StoreAction(option_strings=['-v', '--video'], dest='video', nargs=None, const=None, default='', type=<class 'str'>, choices=None, help=None, 
metavar=None)

args = vars(ap.parse_args())

usage: [-h] -p SHAPE_PREDICTOR [-v VIDEO]
error: the following arguments are required: -p/--shape-predictor

最佳答案

usage: [-h] -p SHAPE_PREDICTOR [-v VIDEO]
error: the following arguments are required: -p/--shape-predictor

是命令行的输出吗?

我不确定,但您可能忘记设置 -p SHAPE_PREDICTOR 标志,这似乎是强制性选项。您的 argparser 返回错误,因为他没有正确的参数

关于python - 为什么在 python 中执行 argparse 时出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56818974/

相关文章:

python - 导入包本质上需要 __init__.py

python - spark 2.1.0 session 配置设置 (pyspark)

python - 跳过数组中的特定索引(或寻址索引间隔)

python - Django聚合

python - 连接单列多个不同形状的文件

python - 大数组的内存错误

python - AttributeError: 'list' 对象没有属性 'click' - 使用 Python 的 Selenium Webdriver

python - 这段 python 代码中的语法错误在哪里?

Python:字符串中的单词在输出中被删除

python - 将对象移动到继承的模型