在本教程中,我们将看到如何解决一个常见的JupyterLab问题:无效的服务器密码。通常我们在尝试打开一个新的Jupyter笔记本服务器时都会遇到这个问题。
接下来的步骤将帮助你解决与Jupyter服务器密码和配置有关的问题。
1.在JupyterLab中设置新密码
要设置或重置JupyterLab的密码,我们可以使用下面的命令:
jupyter server password
2.在Jupyter笔记本中设置密码
对于旧版本的Jupyter Notebook和iPython,我们可以用下面的命令试试:
jupyter notebook password
3.查找Jupyter配置
为了找到Jupyter的配置文件,我们可以使用下面的命令:
jupyter --path
输出结果是:
config:
/home/user/.jupyter
/home/user/PycharmProjects/Pandas-Exercises-Projects/venv/etc/jupyter
/usr/local/etc/jupyter
/etc/jupyter
data:
/home/user/.local/share/jupyter
/home/user/PycharmProjects/Pandas-Exercises-Projects/venv/share/jupyter
/usr/local/share/jupyter
/usr/share/jupyter
runtime:
/home/user/.local/share/jupyter/runtime
我们感兴趣的文件夹是:/home/user/.jupyter ,或者干脆是 -~/.jupyter/ 。在这个文件夹中,我们有这样的文件:
jupyter_notebook_config.json- 检查是否有密码设置jupyter_server_config.json- 检查是否设置了密码jupyter_notebook_config.py- Jupyter的密码配置
4.创建新的配置文件
如果文件不在文件夹中:~/.jupyter/ ,我们可以通过以下方式生成新的Jupyter配置:
jupyter notebook --generate-config
5.设置Jupyter令牌
最后,为了改变Jupyter的密码配置或添加新的认证令牌,我们需要打开文件:
~/.jupyter/jupyter_notebook_config.py
。
取消对c.NotebookApp.allow_password_change 一行的注释:
# This can be set to false to prevent changing passwords from the UI/API.
#c.NotebookApp.allow_password_change = True
并添加新的令牌或通过以下方式禁用认证:
## Token used for authenticating first-time connections to the server.
#
# When no password is enabled, the default is to generate a new, random token.
#
# Setting to an empty string disables authentication altogether, which is NOT
# RECOMMENDED.
#c.NotebookApp.token = '<generated>'
取消注释:#c.NotebookApp.token