天天看点

jupyter运行parse报错报错提示解决方法

报错提示

  • 在使用jupyternotebook运行代码时,碰到如下报错
usage: ipykernel_launcher.py [-h] [-e EPOCHS] [-se START_EPOCH] [-b BATCHSIZE]
                             [-s IMAGESIZE] [-l LEARNING_RATE] [-g GPU]
ipykernel_launcher.py: error: unrecognized arguments: -f /root/.local/share/jupyter/runtime/kernel-6ea6eaa0-62a7-46b2-b140-9f55dcdaed23.json
An exception has occurred, use %tb to see the full traceback.

SystemExit: 2
           
  • 报错的代码是
args = parser.parse_args()
           

解决方法

  • 上述代码是在py文件中执行的
  • 在notebook中,需要修改为
args = parser.parse_args(args=[])