使用 VS-Code 在远程服务器上运行 jupyter 时,提示 kernel 无法启动,同样的报错,根据 vscode-jupyter 官方的 issue #739,建议使用非 root 用户运行,未给出其他方案。
目前我使用的版本中已经支持使用 root 用户来运行,以下做记录。
code 版本:Version: 1.66.2 (system setup) vscode-jupyter 插件版本:Version: 2022.3.1000901801
报错信息如下:
[I 2022-04-26 23:33:29.868 LabApp] JupyterLab extension loaded from /usr/local/python38/lib/python3.8/site-packages/jupyterlab
[I 2022-04-26 23:33:29.868 LabApp] JupyterLab application directory is /usr/local/python38/share/jupyter/lab
[C 23:33:29.875 NotebookApp] Running as root is not recommended. Use --allow-root to bypass.
Failed to run jupyter as observable with args notebook --no-browser --notebook-dir="/root/" --KernelManager.autorestart=False --config=/tmp/502b2fab-1087-414d-9cf6-b292aef4452c/jupyter_notebook_config.py --NotebookApp.iopub_data_rate_limit=10000000000.0
at t.JupyterConnectionWaiter.rejectStartPromise (/root/.vscode-server/extensions/ms-toolsai.jupyter-2022.3.1000901801/out/extension.js:2:362874)
at t._error (/root/.vscode-server/extensions/ms-toolsai.jupyter-2022.3.1000901801/out/extension.js:2:363504)
at t.__tryOrUnsub (/root/.vscode-server/extensions/ms-toolsai.jupyter-2022.3.1000901801/out/extension.js:2:3289560)
at t.error (/root/.vscode-server/extensions/ms-toolsai.jupyter-2022.3.1000901801/out/extension.js:2:3288969)
at t._error (/root/.vscode-server/extensions/ms-toolsai.jupyter-2022.3.1000901801/out/extension.js:2:3287854)
at t.error (/root/.vscode-server/extensions/ms-toolsai.jupyter-2022.3.1000901801/out/extension.js:2:3287548)
at t.error (/root/.vscode-server/extensions/ms-toolsai.jupyter-2022.3.1000901801/out/extension.js:2:3285054)
at /root/.vscode-server/extensions/ms-toolsai.jupyter-2022.3.1000901801/out/extension.js:2:800069] {
category: 'jupyterconnection'
}
报错中主要的有用信息为:Running as root is not recommended. Use --allow-root to bypass.
所以有两种解决方案:
- 使用非 root 用户连接到远程的服务器上进行开发
- 使用 root 用户运行 jupyter
在 vscode-jupyter 中,支持为 jupyter 添加命令行参数,需要在 vscode 的 settings.json 中进行配置。 如下步骤:
按 Ctrl +Shift + P 打开 vscode 的命令面板,输入 settings.json ,选择 Open Settings (JSON) : 在打开的配置文件中,末尾添加 jupyter 命令行参数配置:
...
"jupyter.jupyterCommandLineArguments": [
"--allow-root"
]
...
注意格式,不要忘了在上一行的配置后面添加逗号。
修改完配置后,vscode 右下角会提示重新加载。
按照提示重新加载编辑器后即可正常使用。
|