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
### 在 PyCharm 中配置和使用 Jupyter Notebook #### 安装 Jupyter Notebook 首先,需要确保系统中已安装 Jupyter Notebook。可以通过以下命令完成安装[^1]: ```bash pip install jupyter ``` #### 配置 Jupyter Notebook 以避免每次输入 Token 为了在 PyCharm 中更方便地使用 Jupyter Notebook,可以配置其免去每次启动时输入 Token 的需求。具体方法可以参考相关教程[^2],设置密码并进行适当配置。 #### 在 PyCharm 中集成 Jupyter Notebook PyCharm 支持直接与 Jupyter Notebook 集成,步骤如下: 1. **创建或打开项目**:在 PyCharm 中打开或创建一个项目。 2. **添加 Jupyter Notebook 文件**:右键点击项目目录,选择 `New` -> `Jupyter Notebook`,即可创建一个新的 `.ipynb` 文件。 3. **连接到现有的 Jupyter Server**:如果已有 Jupyter Server,可以在 PyCharm 中通过 `File` -> `Settings` -> `Build, Execution, Deployment` -> `Jupyter` 来添加服务器地址。确保服务器地址正确且可访问[^3]。 4. **解决权限问题**:如果遇到类似 `Running as root is not recommended. Use --allow-root to bypass.` 的错误,需检查是否以管理员身份运行 PyCharm。如果是,则需要退出并以普通用户身份重新运行 PyCharm[^4]。 #### 示例代码块 以下是一个简单的 Python 代码示例,展示如何在 Jupyter Notebook 中运行代码: ```python # 简单的加法运算 a = 5 b = 3 result = a + b print(f"结果是: {result}") ``` #### 注意事项 - 确保 PyCharm 版本支持 Jupyter Notebook 功能,专业版通常提供更好的支持。 - 如果使用 Anaconda 环境,建议通过 Conda 安装 Jupyter Notebook,以确保环境一致性。
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值