Python 3.x 尝试构建参数解析器时出错
我输入的代码和错误消息:Python 3.x 尝试构建参数解析器时出错,python-3.x,jupyter-notebook,argparse,Python 3.x,Jupyter Notebook,Argparse,我输入的代码和错误消息: ap = argparse.ArgumentParser() ap.add_argument("-i", "--image", required=True, help="path to input image to be OCR'd") ap.add_argument("-p", "--preprocess", type=str, default="thresh", help="type of preprocessing to be
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True, help="path to input image to be OCR'd")
ap.add_argument("-p", "--preprocess", type=str, default="thresh", help="type of preprocessing to be
done, choose from blur, linear, cubic or bilateral")
args = vars(ap.parse_args())
错误消息:
####usage: ipykernel_launcher.py [-h] -i IMAGE [-p PREPROCESS]
####ipykernel_launcher.py: error: the following arguments are required: -i/--image
####An exception has occurred, use %tb to see the full traceback.
####SystemExit: 2
您如何提供'--image'参数?您的代码指定了所需的
。命令行是什么?这是一个jupyter笔记本
?是的,它是一个jupyter笔记本。在其他SO问题中已经讨论了argparse
与笔记本的使用。这是困难的,如果不是不可能的话。当您启动jupyter时,如果有参数,您是在向服务器而不是笔记本提供参数argparse
用于编写自己运行的Python脚本,而不是嵌入笔记本或其他交互环境中的脚本。