概述
在jupyter notebook 中使用argparse函数时,可能会出现错误。
问题
error1
usage: ipykernel_launcher.py [-h] [–dir DIR] [–dataset DATASET]
[–data_path PATH] [–batch_size N]
[–num_workers N] [–model MODEL] [–resume CKPT]
[–epochs N] [–save_freq N] [–eval_freq N]
[–lr_init LR] [–momentum M] [–wd WD] [–swa]
[–swa_start N] [–swa_lr LR] [–swa_c_epochs N]
[–seed S]
ipykernel_launcher.py: error: unrecognized arguments: -f /run/user/0/jupyter/kernel-830bbab2-2005-4170-bef0-3586b3877e0a.json
An exception has occurred, use %tb to see the full traceback.
SystemExit: 2
error2
usage: ipykernel_launcher.py [-h] --dir DIR [–dataset DATASET]
[–data_path PATH] [–batch_size N]
[–num_workers N] [–model MODEL] [–resume CKPT]
[–epochs N] [–save_freq N] [–eval_freq N]
[–lr_init LR] [–momentum M] [–wd WD] [–swa]
[–swa_start N] [–swa_lr LR] [–swa_c_epochs N]
[–seed S]
ipykernel_launcher.py: error: the following arguments are required: --dir
An exception has occurred, use %tb to see the full traceback.
SystemExit: 2
解决
error1
添加args=[]
opt=parser.parse_args(args=[])
error2
设置 required=False
出现这种错误是因为 required=True,设置为False即可。
parser.add_argument(’–dir’, type=str, default=None, required=True, help=‘training directory (default: None)’)
最后
以上就是安详网络为你收集整理的Jupyter Notebook使用argparse包 问题的全部内容,希望文章能够帮你解决Jupyter Notebook使用argparse包 问题所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复