1

When learning a piece of python code, some problems have occurred .

code show as below:

parser = argparse.ArgumentParser()

parser.add_argument('--config_path', type=str, default="",
                    help='the location of the data folder')

parser.add_argument('--data_path', type=str, required=True, default="/mnt/Dataset/xView2/v2",
                    help='the location of the data folder')
parser.add_argument('--ckpt_path', type=str, required=True, default="",
                    help='Path to checkpoint')
parser.add_argument('--result_dir', type=str, required=True, default="",
                    help='Path to save result submit and compare iamges')
parser.add_argument('--is_train_data', action='store_true', dest='is_train_data',
                    help='')
parser.add_argument('--is_use_gpu', action='store_true', dest='is_use_gpu',
                    help='')

args = parser.parse_args()

The error is as follows :

runfile('D:/aaa/New_file/test_net.py', wdir='D:/aaa/New_file')
Reloaded modules: models, models.dual_hrnet, xview2, utils
usage: test_net.py [-h] [--config_path CONFIG_PATH] --data_path DATA_PATH
                   --ckpt_path CKPT_PATH --result_dir RESULT_DIR
                   [--is_train_data] [--is_use_gpu]
test_net.py: error: the following arguments are required: --data_path, --ckpt_path, --result_dir
An exception has occurred, use %tb to see the full traceback.

SystemExit: 2


%tb
Traceback (most recent call last):

  File "D:\aaa\New_file\test_net.py", line 41, in <module>
    args = parser.parse_args(args=[])

  File "D:\Anaconda\envs\tensorflow\lib\argparse.py", line 1755, in parse_args
    args, argv = self.parse_known_args(args, namespace)

  File "D:\Anaconda\envs\tensorflow\lib\argparse.py", line 1787, in parse_known_args
    namespace, args = self._parse_known_args(args, namespace)

  File "D:\Anaconda\envs\tensorflow\lib\argparse.py", line 2022, in _parse_known_args
    ', '.join(required_actions))

  File "D:\Anaconda\envs\tensorflow\lib\argparse.py", line 2508, in error
    self.exit(2, _('%(prog)s: error: %(message)s\n') % args)

  File "D:\Anaconda\envs\tensorflow\lib\argparse.py", line 2495, in exit
    _sys.exit(status)

SystemExit: 2

I tried to change args = parser.parse_args() to args = parser.parse_args(args=[]), but the same problem still occurred. I guess it might be because I didn’t set the value of default=" "correctly, Unfortunately I don’t know how to modify.

khelwood
  • 55,782
  • 14
  • 81
  • 108
MoMoMo
  • 11
  • 1
  • 2
  • Are you passing the required arguments to your program when you call it. – khelwood Mar 30 '21 at 08:21
  • `required=True` means that the parameter must be passed in, so is it necessary to set the value of the `default` parameter? Can this value be an address? – MoMoMo Mar 30 '21 at 11:55
  • Where are you running this code? The captured traceback looks a lot like `ipython`, but I'm not familiar with `runfiile`. Is that `sypder`? On providing arguments in `spyder`: https://stackoverflow.com/questions/26679272/how-to-use-argv-with-spyder – hpaulj Mar 30 '21 at 16:49
  • Yes, this is running on `spyder`. This is a part of the code I want to run. It has an error here. Should I try to set the `default` value. Can this value be the address of the image? I can't understand the explanation in the help in the code well, so I don't know the specific setting of the `default` value. Do you have any suggestions? – MoMoMo Mar 31 '21 at 01:50

0 Answers0