Skip to content
Advertisement

How to parse arguments in python (spyder)?

I am following this tutorial and trying to run the below part of the script. I am using python 3.7 and spyder 3.3.4.

ap = argparse.ArgumentParser()
ap.add_argument("-d", "--dataset", required=True,
    help="path to input dataset (i.e., directory of images)")
ap.add_argument("-m", "--model", required=True,
    help="path to output model")
ap.add_argument("-l", "--labelbin", required=True,
    help="path to output label binarizer")
ap.add_argument("-p", "--plot", type=str, default="plot.png",
    help="path to output accuracy/loss plot")
args = vars(ap.parse_args())

I have tried going to Run > Configuration per file and entering the arguments as advised by this post and and this post.

command line options: path1, path2, path3, path4

I filled out the appropriate paths for the arguments above and then ran the script, but go the error below.

usage: train.py [-h] -d DATASET -m MODEL -l LABELBIN [-p PLOT] train.py: error: the following arguments are required: -d/–dataset, -m/–model, -l/–labelbin An exception has occurred, use %tb to see the full traceback. SystemExit: 2

How can I fix this error to run my script appropriately and pass the arguments in spyder?

Advertisement

Answer

You can parse arguments by doing a special run from the settings and putting in the order that the arguments are expected.

Advertisement