import argparse
# construct the argument parse and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True,
help="path to input image")
ap.add_argument("-p", "--prototxt", required=True,
help="path to Caffe 'deploy' prototxt file")
ap.add_argument("-m", "--model", required=True,
help="path to Caffe pre-trained model")
ap.add_argument("-c", "--confidence", type=float, default=0.5,
help="minimum probability to filter weak detections")
args = vars(ap.parse_args())
我正在通过OpenCV运行一个人脸识别示例。 此时我使用“argparse”,并得到此错误。
args = vars(ap.parse_args())
从这个密码。
usage: ipykernel_launcher.py [-h] -i IMAGE -p PROTOTXT -m MODEL
[-c CONFIDENCE]
ipykernel_launcher.py: error: the following arguments are required: -i/--
image, -p/--prototxt, -m/--model
An exception has occurred, use %tb to see the full traceback.
SystemExit: 2
C:\Users\user\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py:2918: UserWarning: To exit: use 'exit', 'quit', or Ctrl-D.
warn("To exit: use 'exit', 'quit', or Ctrl-D.", stacklevel=1)
我该怎么解决?
这是我的电脑环境,使用Jupyter笔记本
如果不共享运行文件的方式,很难回答这个问题。错误是告诉您在运行文件时未找到传入的必需参数。
由于为-i、-p和-m参数指定了
required = True
,因此如果不需要它们来运行程序,则必须始终将它们传入或使它们成为可选参数。在
ipython
会话中:我可以通过修改
sys.argv
来运行此分析器:或与
我经常使用这种方法来测试解析器。
如果这个解析器在脚本中,并且我在没有参数的命令行中运行它,它将打印
usage
,然后退出。这个出口就是ipython
捕获并显示为SystemExit: 2
。相关问题 更多 >
编程相关推荐