ipykernel_launcher.py: error: the following arguments are required: -m/--mode

ipykernel_launcher.py: error: the following arguments are required: -m/--mode

我的代码很长,当我 运行 时,我一直收到这个错误。有谁知道这个错误是关于什么的?

` 用法:ipykernel_launcher.py [-h] -m MODE

ipykernel_launcher.py: error: the following arguments are required: -m/--mode

An exception has occurred, use %tb to see the full traceback.
 
SystemExit: 2`

来自 ipython 帮助:

ipython [subcommand] [options] [-c cmd | -m mod | file] [--] [arg] ...

所以我们可以调用一个脚本来回显 sys.argv

0812:~/mypy$ ipython echo.py -- foo bar
['/home/paul/mypy/echo.py', 'foo', 'bar']

或继续互动会话:

0812:~/mypy$ ipython echo.py -- foo bar
['/home/paul/mypy/echo.py', 'foo', 'bar']
0824:~/mypy$ ipython -i echo.py -- foo bar
Python 3.6.9 (default, Jul 17 2020, 12:50:27) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.16.1 -- An enhanced Interactive Python. Type '?' for help.
['/home/paul/mypy/echo.py', 'foo', 'bar']

In [1]: sys.argv
Out[1]: ['/usr/local/bin/ipython', '-i', 'echo.py', '--', 'foo', 'bar']

sys.argv 包含您的 argparse 解析器将处理的命令行字符串。只需提供它期望的值(如 usage 中指定的那样)。