配置jupyterlab远程访问及其常见问题解决,内核修改
jupyterlab:
- 注意: 以下测试流程基于jupyter(V1.0.0), notebook(V6.0.3)
- pip:
pip install jupyter jupyterlab
- remote access:
- 生成配置文件:
jupyter notebook --generate-config
- 生成口令,访问时输入验证:
# notebook 7.0.x 的版本移除了 'auth',可以采用更低的版本,例如6.0.3 >>>from notebook.auth import passwd >>>passwd()
- 修改配置文件:
$vim ~/.jupyter/jupyter_notebook_config.py c.NotebookApp.ip='*' # 就是设置所有ip皆可访问 c.NotebookApp.password = 'sha1:72... # 刚才复制的那个密文' c.NotebookApp.open_browser = False # 禁止自动打开浏览器 c.NotebookApp.port =8888 #随便指定一个端口
- 访问:浏览器输入url: http://ip:port/
- 生成配置文件:
jupyter notebook调出快捷键:
- 方法1:在命令模式下,按键盘上 h 键。
- 方法2:在界面“Help”菜单下,点击“Keyboard Shortcuts”。
jupyter常见问题:
- jupyter突然奔溃,重新打开,发现之前执行的文件全部丢失,文件恢复到了很久之前的版本
- 解决方案:
%history -g -f notebook_file.ipynb # 将所有执行历史保存到文件notebook_file.ipynb文件中
- jupyter内核修改,官方手册:
- 注意是否是conda环境
- 安装ipykernel:
python -m pip install ipykernel
- 新建kernel:
python -m ipykernel install --user --name=py39
, 如果不定义--name参数的话,默认为python3
# 注意报以下错误时,可以安装支持适当python版本的ipython ImportError: IPython 8.13+ supports Python 3.9 and above, following NEP 29. IPython 8.0-8.12 supports Python 3.8 and above, following NEP 29. When using Python 2.7, please install IPython 5.x LTS Long Term Support version. Python 3.3 and 3.4 were supported up to IPython 6.x. Python 3.5 was supported with IPython 7.0 to 7.9. Python 3.6 was supported with IPython up to 7.16. Python 3.7 was still supported with the 7.x branch.
- 查看kernel:
jupyter kernelspec list
- 删除:
jupyter kernelspec uninstall your_kernel_name
安装目录插件
- 安装 jupyter_contrib_nbextensions
pip install jupyter_contrib_nbextensions
# pip install --no-cache-dir jupyter_contrib_nbextension # 不从缓存文件安装
其他安装方法:https://jupyter-contrib-nbextensions.readthedocs.io/en/latest/install.html
- 配置 nbextension
jupyter contrib nbextension install --user
-
选择 Nbextensions
如果安装成功,但是报404错误,可以查看确实什么文件,然后将相应文件放到该处即可,例如:404 GET /static/components/marked/lib/marked.js?v=20230228170717,将marked.js放到python文件中对应此处即可
目录被遮盖问题:https://github.com/dunovank/jupyter-themes/issues/349,修改样式:lib/python3.8/site-packages/nbclassic/static/custom/custom.css -
勾选 Table of Contents