Jupyter Notebook 是一个强大的交互式计算环境,适合数据科学和编程开发。以下是一些高级功能和使用技巧:
📌 内核管理
- 使用
jupyter kernelspec list
查看已安装内核 - 通过
!pip install
命令安装新内核(如ipykernel
) - 配置多内核并行计算:
jupyter notebook --generate-config
后修改c.NotebookApp.iopub_data_rate_limit
🧩 扩展插件
- 安装 JupyterLab 扩展:
pip install jupyterlab.extensions
- 推荐插件:
jupyterlab-git
: 版本控制集成jupyterlab-variableInspector
: 变量实时监控jupyterlab_code_formatter
: 代码格式化工具
- 启用插件:
jupyter server list
后通过jupyter server extension enable
命令
🛠 自定义配置
- 修改配置文件:
jupyter notebook --generate-config
生成jupyter_notebook_config.py
- 常用配置项:
c.NotebookApp.port
: 设置端口号c.NotebookApp.allow_origin
: 配置跨域访问c.NotebookApp.certfile
和c.NotebookApp.keyfile
: 启用 HTTPS
🔒 安全设置
- 启用密码保护:
jupyter notebook password
- 配置访问限制:
c.NotebookApp.allow_remote_access = False
- 定期更新依赖:
pip install --upgrade jupyter
和pip install --upgrade ipykernel
⚡ 性能优化
- 使用
jupyter nbconvert
批量处理 notebook 文件 - 启用并行计算:
jupyter notebook --parallel
- 配置内存限制:
c.KernelManager.max_starting_kernels = 4
如需了解更多基础操作,请访问 Jupyter入门教程。