使用 args 启动外部 jupyter qtconsole 和 运行 脚本
Launch external jupyter qtconsole and run a script with args
我有一个脚本,它接受一个参数给 运行。通常,我可以使用标准 python 控制台通过以下命令从终端 运行 它:
$python3 myscript.py arg1 &
但是我想在jupyter qtconsole中执行脚本。可以使用以下命令从终端启动外部控制台:
$jupyter qtconsole &
我尝试使用类似的方法启动 jupyter qtconsole 和 运行 myscript.py
,参数 arg1
:
$jupyter qtconsole myscript.py arg1 &
但是没有用。是否有可能做到这一点?怎么样?
来自新 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']
而不是 shell
$ipython3 -i echo_argv.py -- testing 1 2 3
为了 运行 没有任何进一步交互的脚本,我使用常规 $python
调用。无需涉及 jupyter
或 ipython
.
$ python3 echo_argv.py -- testing 1 2 3
来自 qtconsole
配置选项:
KernelManager.kernel_cmd
: List
Default: []
DEPRECATED: Use kernel_name instead.
The Popen Command to launch the kernel. Override this if you have a custom kernel. If kernel_cmd is specified in a configuration file, Jupyter does not pass any arguments to the kernel, because it cannot make any assumptions about the arguments that the kernel understands. In particular, this means that the kernel does not receive the option –debug if it given on the Jupyter command line.
我有一个脚本,它接受一个参数给 运行。通常,我可以使用标准 python 控制台通过以下命令从终端 运行 它:
$python3 myscript.py arg1 &
但是我想在jupyter qtconsole中执行脚本。可以使用以下命令从终端启动外部控制台:
$jupyter qtconsole &
我尝试使用类似的方法启动 jupyter qtconsole 和 运行 myscript.py
,参数 arg1
:
$jupyter qtconsole myscript.py arg1 &
但是没有用。是否有可能做到这一点?怎么样?
来自新 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']
而不是 shell
$ipython3 -i echo_argv.py -- testing 1 2 3
为了 运行 没有任何进一步交互的脚本,我使用常规 $python
调用。无需涉及 jupyter
或 ipython
.
$ python3 echo_argv.py -- testing 1 2 3
来自 qtconsole
配置选项:
KernelManager.kernel_cmd : List Default: []
DEPRECATED: Use kernel_name instead.
The Popen Command to launch the kernel. Override this if you have a custom kernel. If kernel_cmd is specified in a configuration file, Jupyter does not pass any arguments to the kernel, because it cannot make any assumptions about the arguments that the kernel understands. In particular, this means that the kernel does not receive the option –debug if it given on the Jupyter command line.