Running as root is not recommended. Use --allow-root to bypass

本文介绍如何使用root权限运行Jupyter Notebook,并通过配置文件设置访问密码、IP地址、端口号等参数,确保Jupyter Notebook的安全运行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

首先输入,查看配置文件位置

[as-pc as]# jupyter notebook --generate-config --allow-root 

Overwrite /root/.jupyter/jupyter_notebook_config.py with default config? [y/N]y
Writing default config to: /root/.jupyter/jupyter_notebook_config.py

接下来打开配置文件

gedit /root/.jupyter/jupyter_notebook_config.py

找到这一行

#c.NotebookApp.allow_root = False  

去掉#,并修改成True即可解决root权限运行的问题

c.NotebookApp.allow_root =True

保存,重新运行程序

jupyter notebook

设置访问密码
打开 ipython 输入

from notebook.auth import passwd
passwd()

然后根据提示输入2次密码
Enter password: ········
Verify password: ········
这里写图片描述
然后复制 ‘sha1:f5643****************************’ 粘贴至配置文件(记得去掉 #

c.NotebookApp.password = u'sha1:f5*****************************'

更多设置如下

c.NotebookApp.ip = 'localhost'
c.NotebookApp.open_browser = TrueTrue:启动时自动打开浏览器,False:需手动打开浏览器访问http://localhost:8888/tree)
c.NotebookApp.port = 8888(端口设置)
[I 2025-07-14 08:43:19.216 LabApp] JupyterLab application directory is /usr/local/share/jupyter/lab [I 2025-07-14 08:43:19.216 LabApp] Extension Manager is 'pypi'. [I 2025-07-14 08:43:19.219 ServerApp] jupyterlab | extension was successfully loaded. [I 2025-07-14 08:43:19.222 ServerApp] notebook | extension was successfully loaded. [C 2025-07-14 08:43:19.224 ServerApp] Running as root is not recommended. Use --allow-root to bypass. 正在启动数据分析环境... 配置中文字体... 找到中文字体: /usr/share/fonts/truetype/wqy/wqy-zenhei.ttc 已清除缓存: fontlist-v330.json 中文字体配置完成! 启动Jupyter Lab... 访问地址: http://localhost:22001 Token: spacy2024 [I 2025-07-14 08:44:20.675 ServerApp] jupyter_lsp | extension was successfully linked. [I 2025-07-14 08:44:20.680 ServerApp] jupyter_server_terminals | extension was successfully linked. [W 2025-07-14 08:44:20.681 LabApp] 'ip' has moved from NotebookApp to ServerApp. This config will be passed to ServerApp. Be sure to update your config before our next release. [W 2025-07-14 08:44:20.681 LabApp] 'port' has moved from NotebookApp to ServerApp. This config will be passed to ServerApp. Be sure to update your config before our next release. [W 2025-07-14 08:44:20.681 LabApp] 'port' has moved from NotebookApp to ServerApp. This config will be passed to ServerApp. Be sure to update your config before our next release. [W 2025-07-14 08:44:20.681 LabApp] 'allow_root' has moved from NotebookApp to ServerApp. This config will be passed to ServerApp. Be sure to update your config before our next release. [W 2025-07-14 08:44:20.681 LabApp] 'token' has moved from NotebookApp to ServerApp. This config will be passed to ServerApp. Be sure to update your config before our next release. [W 2025-07-14 08:44:20.681 LabApp] 'password' has moved from NotebookApp to ServerApp. This config will be passed to ServerApp. Be sure to update your config before our next release. [W 2025-07-14 08:44:20.681 LabApp] 'allow_origin' has moved from NotebookApp to ServerApp. This config will be passed to ServerApp. Be sure to update your config before our next release. [W 2025-07-14 08:44:20.681 LabApp] 'allow_remote_access' has moved from NotebookApp to ServerApp. This config will be passed to ServerApp. Be sure to update your config before our next release. [W 2025-07-14 08:44:20.681 LabApp] 'notebook_dir' has moved from NotebookApp to ServerApp. This config will be passed to ServerApp. Be sure to update your config before our next release. [W 2025-07-14 08:44:20.681 LabApp] 'disable_check_xsrf' has moved from NotebookApp to ServerApp. This config will be passed to ServerApp. Be sure to update your config before our next release. [W 2025-07-14 08:44:20.681 LabApp] 'contents_manager_class' has moved from NotebookApp to ServerApp. This config will be passed to ServerApp. Be sure to update your config before our next release. [W 2025-07-14 08:44:20.685 ServerApp] jupyterlab | error linking extension: The 'contents_manager_class' trait of <jupyter_server.serverapp.ServerApp object at 0x7fae37602ac0> instance must be a type, but 'notebook.services.contents.largefilemanager.LargeFileManager' could not be imported Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/traitlets/traitlets.py", line 2139, in validate value = self._resolve_string(value) File "/usr/local/lib/python3.9/site-packages/traitlets/traitlets.py", line 2015, in _resolve_string return import_item(string) File "/usr/local/lib/python3.9/site-packages/traitlets/utils/importstring.py", line 33, in import_item module = __import__(package, fromlist=[obj]) ModuleNotFoundError: No module named 'notebook.services' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/jupyter_server/extension/manager.py", line 381, in link_extension extension.link_all_points(self.serverapp) File "/usr/local/lib/python3.9/site-packages/jupyter_server/extension/manager.py", line 258, in link_all_points self.link_point(point_name, serverapp) File "/usr/local/lib/python3.9/site-packages/jupyter_server/extension/manager.py", line 243, in link_point point.link(serverapp) File "/usr/local/lib/python3.9/site-packages/jupyter_server/extension/manager.py", line 158, in link linker(serverapp) File "/usr/local/lib/python3.9/site-packages/jupyter_server/extension/application.py", line 412, in _link_jupyter_server_extension self.serverapp.update_config(self.config) File "/usr/local/lib/python3.9/site-packages/traitlets/config/configurable.py", line 244, in update_config self._load_config(config) File "/usr/local/lib/python3.9/site-packages/traitlets/config/configurable.py", line 193, in _load_config setattr(self, name, deepcopy(config_value)) File "/usr/local/lib/python3.9/site-packages/traitlets/traitlets.py", line 716, in __set__ self.set(obj, value) File "/usr/local/lib/python3.9/site-packages/traitlets/traitlets.py", line 690, in set new_value = self._validate(obj, value) File "/usr/local/lib/python3.9/site-packages/traitlets/traitlets.py", line 722, in _validate value = self.validate(obj, value) File "/usr/local/lib/python3.9/site-packages/traitlets/traitlets.py", line 2141, in validate raise TraitError( traitlets.traitlets.TraitError: The 'contents_manager_class' trait of <jupyter_server.serverapp.ServerApp object at 0x7fae37602ac0> instance must be a type, but 'notebook.services.contents.largefilemanager.LargeFileManager' could not be imported [I 2025-07-14 08:44:20.690 ServerApp] notebook | extension was successfully linked. [I 2025-07-14 08:44:20.872 ServerApp] notebook_shim | extension was successfully linked. [I 2025-07-14 08:44:20.888 ServerApp] notebook_shim | extension was successfully loaded. [I 2025-07-14 08:44:20.890 ServerApp] jupyter_lsp | extension was successfully loaded. [I 2025-07-14 08:44:20.891 ServerApp] jupyter_server_terminals | extension was successfully loaded. [I 2025-07-14 08:44:20.892 LabApp] JupyterLab extension loaded from /usr/local/lib/python3.9/site-packages/jupyterlab [I 2025-07-14 08:44:20.892 LabApp] JupyterLab application directory is /usr/local/share/jupyter/lab [I 2025-07-14 08:44:20.893 LabApp] Extension Manager is 'pypi'. [I 2025-07-14 08:44:20.896 ServerApp] jupyterlab | extension was successfully loaded. [I 2025-07-14 08:44:20.899 ServerApp] notebook | extension was successfully loaded. [C 2025-07-14 08:44:20.900 ServerApp] Running as root is not recommended. Use --allow-root to bypass. PS C:\Users\3090\Desktop\Docker\spacy-metabase-docker>
07-15
(d2l_env) root@wang-VMware-Virtual-Platform:/home/wang# git clone https://github.com/d2l-ai/d2l-zh-pytorch-slides.git 正克隆到 'd2l-zh-pytorch-slides'... remote: Enumerating objects: 9118, done. remote: Counting objects: 100% (262/262), done. remote: Compressing objects: 100% (78/78), done. remote: Total 9118 (delta 201), reused 239 (delta 184), pack-reused 8856 (from 1) 接收对象中: 100% (9118/9118), 83.23 MiB | 10.46 MiB/s, 完成. 处理 delta 中: 100% (7199/7199), 完成. (d2l_env) root@wang-VMware-Virtual-Platform:/home/wang# jupyter notebook [I 2025-08-18 15:02:41.443 ServerApp] jupyter_lsp | extension was successfully linked. [I 2025-08-18 15:02:41.447 ServerApp] jupyter_server_terminals | extension was successfully linked. [I 2025-08-18 15:02:41.451 ServerApp] jupyterlab | extension was successfully linked. [I 2025-08-18 15:02:41.454 ServerApp] notebook | extension was successfully linked. [I 2025-08-18 15:02:41.455 ServerApp] Writing Jupyter server cookie secret to /root/.local/share/jupyter/runtime/jupyter_cookie_secret [I 2025-08-18 15:02:41.887 ServerApp] notebook_shim | extension was successfully linked. [I 2025-08-18 15:02:41.915 ServerApp] notebook_shim | extension was successfully loaded. [I 2025-08-18 15:02:41.917 ServerApp] jupyter_lsp | extension was successfully loaded. [I 2025-08-18 15:02:41.917 ServerApp] jupyter_server_terminals | extension was successfully loaded. [I 2025-08-18 15:02:41.924 LabApp] JupyterLab extension loaded from /root/miniconda3/envs/d2l_env/lib/python3.11/site-packages/jupyterlab [I 2025-08-18 15:02:41.924 LabApp] JupyterLab application directory is /root/miniconda3/envs/d2l_env/share/jupyter/lab [I 2025-08-18 15:02:41.924 LabApp] Extension Manager is 'pypi'. [I 2025-08-18 15:02:41.986 ServerApp] jupyterlab | extension was successfully loaded. [I 2025-08-18 15:02:41.989 ServerApp] notebook | extension was successfully loaded. [C 2025-08-18 15:02:41.989 ServerApp] Running as root is not recommended. Use --allow-root to bypass.
08-19
(d2l_env) root@wang-VMware-Virtual-Platform:/home/wang# jupyter notebook [I 2025-08-18 15:31:49.084 ServerApp] jupyter_lsp | extension was successfully linked. [I 2025-08-18 15:31:49.087 ServerApp] jupyter_server_terminals | extension was successfully linked. [I 2025-08-18 15:31:49.091 ServerApp] jupyterlab | extension was successfully linked. [I 2025-08-18 15:31:49.095 ServerApp] notebook | extension was successfully linked. [I 2025-08-18 15:31:49.334 ServerApp] notebook_shim | extension was successfully linked. [I 2025-08-18 15:31:49.347 ServerApp] notebook_shim | extension was successfully loaded. [I 2025-08-18 15:31:49.348 ServerApp] jupyter_lsp | extension was successfully loaded. [I 2025-08-18 15:31:49.349 ServerApp] jupyter_server_terminals | extension was successfully loaded. [I 2025-08-18 15:31:49.351 LabApp] JupyterLab extension loaded from /root/miniconda3/envs/d2l_env/lib/python3.11/site-packages/jupyterlab [I 2025-08-18 15:31:49.351 LabApp] JupyterLab application directory is /root/miniconda3/envs/d2l_env/share/jupyter/lab [I 2025-08-18 15:31:49.352 LabApp] Extension Manager is 'pypi'. [I 2025-08-18 15:31:49.391 ServerApp] jupyterlab | extension was successfully loaded. [I 2025-08-18 15:31:49.394 ServerApp] notebook | extension was successfully loaded. [I 2025-08-18 15:31:49.394 ServerApp] The port 8888 is already in use, trying another port. [I 2025-08-18 15:31:49.395 ServerApp] The port 8889 is already in use, trying another port. [C 2025-08-18 15:31:49.395 ServerApp] Running as root is not recommended. Use --allow-root to bypass. (d2l_env) root@wang-VMware-Virtual-Platform:/home/wang# jupyter notebook --ip=0.0.0.0 --port=8888 [I 2025-08-18 15:32:09.743 ServerApp] jupyter_lsp | extension was successfully linked. [I 2025-08-18 15:32:09.747 ServerApp] jupyter_server_terminals | extension was successfully linked. [I 2025-08-18 15:32:09.750 ServerApp] jupyterlab | extension was successfully linked. [I 2025-08-18 15:32:09.753 ServerApp] notebook | extension was successfully linked. [I 2025-08-18 15:32:09.993 ServerApp] notebook_shim | extension was successfully linked. [I 2025-08-18 15:32:10.006 ServerApp] notebook_shim | extension was successfully loaded. [I 2025-08-18 15:32:10.008 ServerApp] jupyter_lsp | extension was successfully loaded. [I 2025-08-18 15:32:10.009 ServerApp] jupyter_server_terminals | extension was successfully loaded. [I 2025-08-18 15:32:10.011 LabApp] JupyterLab extension loaded from /root/miniconda3/envs/d2l_env/lib/python3.11/site-packages/jupyterlab [I 2025-08-18 15:32:10.011 LabApp] JupyterLab application directory is /root/miniconda3/envs/d2l_env/share/jupyter/lab [I 2025-08-18 15:32:10.011 LabApp] Extension Manager is 'pypi'. [I 2025-08-18 15:32:10.049 ServerApp] jupyterlab | extension was successfully loaded. [I 2025-08-18 15:32:10.052 ServerApp] notebook | extension was successfully loaded. [I 2025-08-18 15:32:10.053 ServerApp] The port 8888 is already in use, trying another port. [I 2025-08-18 15:32:10.053 ServerApp] The port 8889 is already in use, trying another port. [C 2025-08-18 15:32:10.053 ServerApp] Running as root is not recommended. Use --allow-root to bypass. (d2l_env) root@wang-VMware-Virtual-Platform:/home/wang# jupyter notebook --allow-root [I 2025-08-18 15:32:33.381 ServerApp] jupyter_lsp | extension was successfully linked. [I 2025-08-18 15:32:33.384 ServerApp] jupyter_server_terminals | extension was successfully linked. [I 2025-08-18 15:32:33.389 ServerApp] jupyterlab | extension was successfully linked. [I 2025-08-18 15:32:33.392 ServerApp] notebook | extension was successfully linked. [I 2025-08-18 15:32:33.630 ServerApp] notebook_shim | extension was successfully linked. [I 2025-08-18 15:32:33.643 ServerApp] notebook_shim | extension was successfully loaded. [I 2025-08-18 15:32:33.644 ServerApp] jupyter_lsp | extension was successfully loaded. [I 2025-08-18 15:32:33.645 ServerApp] jupyter_server_terminals | extension was successfully loaded. [I 2025-08-18 15:32:33.647 LabApp] JupyterLab extension loaded from /root/miniconda3/envs/d2l_env/lib/python3.11/site-packages/jupyterlab [I 2025-08-18 15:32:33.647 LabApp] JupyterLab application directory is /root/miniconda3/envs/d2l_env/share/jupyter/lab [I 2025-08-18 15:32:33.647 LabApp] Extension Manager is 'pypi'. [I 2025-08-18 15:32:33.685 ServerApp] jupyterlab | extension was successfully loaded. [I 2025-08-18 15:32:33.688 ServerApp] notebook | extension was successfully loaded. [I 2025-08-18 15:32:33.688 ServerApp] The port 8888 is already in use, trying another port. [I 2025-08-18 15:32:33.688 ServerApp] The port 8889 is already in use, trying another port. [I 2025-08-18 15:32:33.689 ServerApp] Serving notebooks from local directory: /home/wang [I 2025-08-18 15:32:33.689 ServerApp] Jupyter Server 2.16.0 is running at: [I 2025-08-18 15:32:33.689 ServerApp] http://localhost:8890/tree?token=1e0460c42c80c5618f39a5208bc667b8765429bd0a202b55 [I 2025-08-18 15:32:33.689 ServerApp] http://127.0.0.1:8890/tree?token=1e0460c42c80c5618f39a5208bc667b8765429bd0a202b55 [I 2025-08-18 15:32:33.689 ServerApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation). [C 2025-08-18 15:32:33.810 ServerApp] To access the server, open this file in a browser: file:///root/.local/share/jupyter/runtime/jpserver-10883-open.html Or copy and paste one of these URLs: http://localhost:8890/tree?token=1e0460c42c80c5618f39a5208bc667b8765429bd0a202b55 http://127.0.0.1:8890/tree?token=1e0460c42c80c5618f39a5208bc667b8765429bd0a202b55 [I 2025-08-18 15:32:33.823 ServerApp] Skipped non-installed server(s): bash-language-server, dockerfile-language-server-nodejs, javascript-typescript-langserver, jedi-language-server, julia-language-server, pyright, python-language-server, python-lsp-server, r-languageserver, sql-language-server, texlab, typescript-language-server, unified-language-server, vscode-css-languageserver-bin, vscode-html-languageserver-bin, vscode-json-languageserver-bin, yaml-language-server Opening "/root/.local/share/jupyter/runtime/jpserver-10883-open.html" with Text Editor (text/html) (gnome-text-editor:11112): Gtk-WARNING **: 15:32:34.255: Unable to acquire session bus: 执行子进程“dbus-launch”失败(没有那个文件或目录) mkdir: cannot create directory ‘/run/user/0’: Permission denied Authorization required, but no authorization protocol specified Error: cannot open display: :0 mkdir: cannot create directory ‘/run/user/0’: Permission denied Authorization required, but no authorization protocol specified Error: cannot open display: :0 /usr/bin/xdg-open: 882: iceweasel: not found /usr/bin/xdg-open: 882: seamonkey: not found /usr/bin/xdg-open: 882: mozilla: not found /usr/bin/xdg-open: 882: epiphany: not found /usr/bin/xdg-open: 882: konqueror: not found /usr/bin/xdg-open: 882: chromium: not found /usr/bin/xdg-open: 882: chromium-browser: not found /usr/bin/xdg-open: 882: google-chrome: not found /usr/bin/xdg-open: 882: www-browser: not found /usr/bin/xdg-open: 882: links2: not found /usr/bin/xdg-open: 882: elinks: not found /usr/bin/xdg-open: 882: links: not found /usr/bin/xdg-open: 882: lynx: not found /usr/bin/xdg-open: 882: w3m: not found xdg-open: no method available for opening 'file:///root/.local/share/jupyter/runtime/jpserver-10883-open.html' context mismatch in svga_surface_destroy
最新发布
08-19
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值