Jupyter Notebook的配置(密码端口+远程登陆+nbextension)

1 生成配置文件

linux和mac系统打开终端
windows系统打开anaconda自带的终端

jupyter notebook --generate-config

此时系统会生成 ~/.jupyter/ 这个隐藏文件夹,且文件夹中生成了一个jupyter的配置文件jupyter_notebook_config.py

2 配置密码+端口+远程登陆+工作目录+启动mathjax

2.1 生成jupyter的密码

打开IDE或者命令行,输入如下命令

from notebook.auth import passwd
passwd()
# 此时需要输入两次密码(一次设置,一次确认),然后生成sha1的密文,拷贝下来。
# Enter password: ········
# Verify password: ········
# sha1:b11ba7ae862e:6eeb922ef6b770e43a1c90922ba341faaaaaaaa

输入passwd()后需要两次键入密码,之后会产生一段密文

2.2 修改配置文件jupyter_notebook_config.py

打开jupyter_notebook_config.py,滚动到文件最后一行,加入下面的配置选项

# 允许所有ip访问
c.NotebookApp.ip='*' 

# 密码 2.1中生成'sha1:xxxx"那一大串,复制时包括sha1 
c.NotebookApp.password = 'sha1:0d00e0994444:3aeecafab4d91260d42647df8df4c3859a3430a9' 

# 是否打开浏览器 
c.NotebookApp.open_browser = False 

# 指定端口 jupyter的默认端口为8888
c.NotebookApp.port = 10000

# 启用 MathJax 
c.NotebookApp.enable_mathjax = True 

# 修改工作空间文件夹  '/home/jupyter/'改成你的目录
c.NotebookApp.notebook_dir = '/home/jupyter/'

2.3 启动jupyter notebook

在服务器上使用jupyter notebook启动

nohup jupyter notebook --no-browser --allow-root --ip=0.0.0.0 --port=8080 --notebook-dir=/ &

然后本机通过http://address_of_remote:10000远程访问即可,登录界面需要输入设置的密码。

3 Jupyter安装nbextensions

如果你已经安装了,先执行卸载命令:

pip uninstall jupyter_contrib_nbextensions
pip uninstall jupyter_nbextensions_configurator

打开Anaconda Prompt窗口,执行第一个命令,用于安装nbextensions:

pip install jupyter_contrib_nbextensions

再执行第二个命令,用于安装 javascript and css files

jupyter contrib nbextension install --user

最后执行,用于安装configurator

pip install jupyter_nbextensions_configurator

然后重新启动Jupyter Notebook后,就会发现已经有Nbextensions标签了。

常用扩展功能,勾选上即可:
最常用功能说明,建议勾选上:

  • Collapsible headings 折叠标题
  • Notify 通知机制,跑一些耗时较久的任务,完成后通知
  • Codefolding 折叠代码
  • Zen mode extension 隐藏活动状态栏,方便注意代码
  • Execute time extension 显示运行的时间
posted @ 2019-11-16 09:32  Yumeka  阅读(4938)  评论(0编辑  收藏  举报