问题
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.
回答1:
When running sample.py
, you need to specify the -i
/--image
argument:
python sample.py --image image/cat.png
If you want the image
argument to be optional, remove required=True
:
ap.add_argument("-i", "--image", help="path to the input image")
来源:https://stackoverflow.com/questions/55531306/how-to-fix-error-the-following-arguments-are-required-i-image