Jupyter 笔记本内核仅在作为 systemctl 服务运行时出现错误

问题描述 投票:0回答:1

我有以下服务文件:

[Unit]
Description=Jupyter-Notebook Daemon

[Service]
Type=simple
ExecStart=/bin/bash -c "~/mambaforge/envs/main/bin/jupyter-notebook --no-browser --notebook-dir=~/Code/notebooks"
User=<my_user>
PIDFile=/run/jupyter-notebook.pid
Restart=on-failure
RestartSec=60s

[Install]
WantedBy=multi-user.target

(注意我使用 mambaforge 而不是 miniconda)。当我在命令行中按原样运行 ExecStart 下的命令时,服务器启动,并且在打开笔记本时,内核会正确初始化。

但是,当它作为服务启动时(例如

sudo systemctl start jupyter-service
),内核无法连接。它给出了很长的错误消息,但重要的部分是:

FileNotFoundError: [Errno 2] No such file or directory: '~/miniconda3/envs/main/bin/python'

注意它如何尝试从 miniconda3(不存在)运行! 这是为什么?

供运行时参考

jupyter kernelspec list
我得到了正确的内核路径:

Available kernels:
  %s    %s python3        ~/mambaforge/envs/main/share/jupyter/kernels/python3

并使用

cat ~/mambaforge/envs/main/share/jupyter/kernels/python3/kernel.json
返回:

{
 "argv": [
  "~/mambaforge/envs/main/bin/python",
  "-m",
  "ipykernel_launcher",
  "-f",
  "{connection_file}"
 ],
 "display_name": "Python 3 (ipykernel)",
 "language": "python",
 "metadata": {
  "debugger": true
 }
}

我想知道Jupyter在哪里寻找python内核?为什么?

python python-3.x linux jupyter-notebook jupyter
1个回答
0
投票

我在使用 powershell 交互式内核时遇到了类似的问题。我必须在与我的用户路径匹配的服务文件中添加“环境”。

echo $PATH

在.service文件中:

[Service]
Environment="PATH=yourResultsFromTheEcho"

本质上,dotnet 的 Jupyter 内核需要访问 /home/user/.dotnet/tools,其中“dotnet-interactive”的可执行文件所在

参考:https://medium.com/@desjoerdhaan/manage-your-jupyter-server-with-systemd-9914ff39049d

© www.soinside.com 2019 - 2024. All rights reserved.