从一个新的qtconsole
:
In [14]: sys.argv
Out[14]:
['/usr/local/lib/python3.5/dist-packages/ipykernel/__main__.py',
'-f',
'/run/user/1000/jupyter/kernel-25521.json']
In [16]: %connect_info
{
"stdin_port": 57643,
"key": "bcc03e84-7c43-4fbe-84d7-6c005aa37930",
"ip": "127.0.0.1",
"transport": "tcp",
"iopub_port": 45064,
"hb_port": 46748,
"control_port": 39960,
"kernel_name": "",
"shell_port": 57532,
"signature_scheme": "hmac-sha256"
}
Paste the above JSON into a file, and connect with:
$> jupyter <app> --existing <file>
or, if you are local, you can connect with just:
$> jupyter <app> --existing kernel-25521.json
or even just:
$> jupyter <app> --existing
if this is the most recent Jupyter kernel you have started.
所以如果我不这样做
$ jupyter console --existing kernel-25521.json
我得到一个与 qtconsole 共享内核的控制台。如果我在其中一个中导入一个模块或创建一个变量,那么它在另一个中可用。
通常,当我想在其中运行脚本时,ipython
我会使用%run
魔法,而不是尝试将其包含在命令行中。
In [32]: %run echo_argv.py testing 1 2 3
['echo_argv.py', 'testing', '1', '2', '3']
而不是外壳
$ipython3 -i echo_argv.py -- testing 1 2 3
要在没有任何进一步交互的情况下运行脚本,我使用常规$python
调用。无需涉及jupyter
或ipython
。
$ python3 echo_argv.py -- testing 1 2 3
从qtconsole
配置选项:
KernelManager.kernel_cmd :列表默认值:[]
已弃用:改用 kernel_name。
用于启动内核的 Popen 命令。如果您有自定义内核,请覆盖它。如果在配置文件中指定了 kernel_cmd,则Jupyter 不会将任何参数传递给内核,因为它无法对内核理解的参数做出任何假设。特别是,这意味着如果在 Jupyter 命令行上给出了选项 –debug,内核将不会收到该选项。