或曰:“以德报怨,何如?”
子曰:“何以报德? 以直报怨,以德报德。”
——《论语·宪问》
- Ubuntu 20.04 安装 Jupyter Notebook
- 远程访问 Jupyter Notebook
- 优化jupyter notebook使用体验 (自动补全/高亮/主题设置 等)
TL;DR
1 | pip install notebook jupyterthemes jupyter_contrib_nbextensions jupyter_nbextensions_configurator && jupyter contrib nbextension install --user && jupyter nbextensions_configurator enable --user && jupyter notebook --generate-config && echo "##########################################\nmodify [~/.jupyter/jupyter_notebook_config.py]\nuse [jt] to change jupyter's theme\n##########################################" |
Ubuntu 20.04 安装 Jupyter Notebook
1 | 使用Anaconda安装 |
Ubuntu 20.04 配置 Jupyter Notebook
生成配置文件
1
jupyter notebook --generate-config
创建密码
使用python中的passwd()创建密码,终端输入ipython打开ipython并输入:
1
2
3
4
5
6from notebook.auth import passwd
passwd()
Enter password:
Verify password:
'argon2:$argon2i$v=19$m=16,t=2,p=1$Wjl1aWdvUnBjSUhMZ2tueA$v2UhDjB4WQhgvCunf0IxVQ'复制显示的密码 (‘argon2:…’ 包括引号)。我的运行环境为python3.8,
notebook.auth.passwd
已经默认使用argon2
算法代替SHA1
算法生成的默认密码了。关于如何安全的存储密码以及使用何种算法总是有很多的争论:MD5、SHA1,SHA256、PBKDF2,Bcrypt、Scrypt、Argon2、明文?具体可以移步[译] 密码哈希的方法:PBKDF2,Scrypt,Bcrypt 和 ARGON2,简介明了。修改 Jupyter Notebook 的配置文件
打开配置文
~/.jupyter/jupyter_notebook_config.py
在该文件中做如下修改或直接在文件尾端添加:1
2
3
4
5c.NotebookApp.allow_remote_access = True #允许远程连接
c.NotebookApp.ip='*' # 设置所有ip皆可访问
c.NotebookApp.password = 'argon2:...' #之前复制的密码
c.NotebookApp.open_browser = False # 禁止自动打开浏览器
c.NotebookApp.port =8888 #任意指定一个端口运行并远程访问 Jupyter Notebook
启动 Jupyter Notebook
终端运行
jupyter-notebook
或使用 nohup 后台运行
nohup jupyter-notebook > ~/jupyter.log 2>&1 &
或使用 screen 后台运行
远程访问 Jupyter Notebook
本地浏览器输入 <服务器地址>:<配置文件中设定的端口> 即可访问jupyter notebook。
Jupyter Notebook 优化配置 添加插件
探索 Jupyter Notebook 的自动补全功能以及主题功能:
插件配置
Jupyter Notebook 是默认没有代码自动补全功能的,但是它有一个扩展集合——nbextensions
1
2
3
4
5安装 jupyter_contrib_nbextensions 和 jupyter_nbextensions_configurator
pip install jupyter_contrib_nbextensions
pip install jupyter_nbextensions_configurator
jupyter contrib nbextension install --user
jupyter nbextensions_configurator enable --user安装好 jupyter_contrib_nbextensions 和 nbextensions_configurator 后,重新启动 notebook 后,就可以在 notebook 的 home 页面看到 NBextensions 的标签。在这个选项中,有很多的拓展配置。比如说代码折叠,代码补全,选中高亮等 。
主题配置
关于 Jupyter Notebook 的主题,需要安装jupyter-themes库,可以用pip安装也可以用conda安装。这个库可以让你的 Jupyter Notebook 焕然一新。只需要在命令行中输入命令jt以及它的参数,就可以配置相关的主题配色。
1
2
3
4
5
6
7
8安装jupyter主题
pip install jupyterthemes
加载可用主题列表
jt -l
选择你想要的主题
jt -t <name of the theme> # 如 jt -t chesterish
回到原来的主题
jt -r当前可用主题如下:
- chesterish
- grade3
- gruvboxd
- gruvboxl
- monokai
- oceans16
- onedork
- solarizedd
- solarizedl
Ubuntu 20.04 安装/运行 Jupyter Lab
1 | 使用Anaconda安装 |
Ubuntu 20.04 配置 Jupyter Lab Kite
Kite将AI驱动的代码自动补齐功能添加到代码编辑器(IDE)中,从而为开发人员提供了超能力。
1 | 安装 Kite for Jupyter Lab |
Reference
- Ubuntu安装Jupyter notebook——开启远程访问
- 优化你的jupyter notebook使用体验–自动补全+主题设置
- jupyter-themes库
- Jupyter 各种主题
- [译] 密码哈希的方法:PBKDF2,Scrypt,Bcrypt 和 ARGON2
- Kite: Code Faster. Stay in Flow.