Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 尝试构建参数解析器时出错_Python 3.x_Jupyter Notebook_Argparse - Fatal编程技术网

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脚本,而不是嵌入笔记本或其他交互环境中的脚本。