安装配置
参考:https://zhuanlan.zhihu.com/p/33105153
https://github.com/TommyZihao/zihaopython
官方文档:https://jupyter-notebook.readthedocs.io/en/stable/
启动命令
jupyter notebook # 会自动打开浏览器
jupyter notebook --no-browser
指定端口启动
jupyter notebook --port <port_number>
生成默认配置文件
jupyter notebook --generate-config
Writing default config to: /Users/kulitoris/.jupyter/jupyter_notebook_config.py
修改配置文件
c.NotebookApp.ip='*' # 允许任何ip访问,默认只允许本地访问
c.NotebookApp.port =8888 # 可自行指定一个端口, 访问时使用该端口.
关联conda
参考:https://zhuanlan.zhihu.com/p/139776843
conda update notebook
conda install nb_conda
jupyter serverextension disable nb_conda
jupyter serverextension enable nb_conda
conda install -n python_env ipykernel
报错EnvironmentLocationNotFound: Not a conda environment: /root/anaconda3/envs/anaconda3的解决方案:https://blog.csdn.net/why123wh/article/details/106019105
修改文件路径:
~/anaconda3/pkgs/nb_conda-2.2.1-py38_1/lib/python3.8/site-packages/nb_conda/envmanager.py
可能用到:conda update -n base conda -c conda-forge更新conda base环境下的所有包
插件管理,安装jupyter_contrib_nbextensions
参考:https://zhuanlan.zhihu.com/p/258976438
https://github.com/ipython-contrib/jupyter_contrib_nbextensions
https://github.com/Jupyter-contrib/jupyter_nbextensions_configurator
# 安装jupyter_contrib_nbextensions
conda install -c conda-forge jupyter_contrib_nbextensions
jupyter contrib nbextension install --user
# 安装jupyter_nbextensions_configurator(辅助管理面板)
conda install -c conda-forge jupyter_nbextensions_configurator
常用插件
插件 | 功能 |
---|---|
table of contents | 左侧显示目录 |
Hinterland | 按tab自动补全 |
Codefolding | 代码折叠 |
Collapsible Headings | 笔记本按标题折叠。很方便,适合功能复杂的代码。 |
Highlight selected word | 高亮选中的词 |
Highlighter | Markdown文本高亮 |
Code prettify | 格式化/美化代码。按照PEP8 Python编码规范,需要安装YAPF模块。用pip install yapf即可。 |
ExecuteTime | 显示执行时间 |
Toggle all line numbers | 显示代码行号。 |
Variable Inspector | 检查变量。使用浮窗表格收集变量信息。类似Matlab的功能了,弥补了一大遗憾。 |
Snippets menu | 快速添加python、常见模块的example、document等等。 |
Tree Filter | 在文件界面过滤文件 |
Runtools | Cell标记、锁定 |
Scratchpad | 新开一个窗口,在数据分析过程中非常有用,比如你画了个图,想对照着图看绘图数据、或者看看修改参数后的效果图。快捷键:Ctrl键+B键 |
使用
回车,从命令模式进入编辑模式
esc,从编辑模式退回到命令模式
命令模式命令
ctrl+回车 运行代码块或渲染md块
shift + 回车 运行代码块或渲染md块并跳到下一个单元格
alt + 回车 运行代码块或渲染md块并新建一个单元格跳过去
x 剪切单元格
c 复制单元格
dd 删除单元格
l 显示代码行号
shift + v 粘贴到上面
v 粘贴到当前块
z 撤销
m 切换成markdown单元格
y 切换成代码单元格
h 查看快捷键
b 在下方新建单元格
a 在上方新建单元格
o 切换显示模式/隐藏输出
Magic Commands
参考:https://www.cnblogs.com/bind/archive/2004/01/13/11958317.html
IPython官方文档:https://ipython.readthedocs.io/en/stable/interactive/magics.html
%lsmagic 列出当前可用的魔术命令
%magic 显示魔术命令的帮助
%matplotlib 设置matplotlib的工作方式
%pwd 返回当前工作路径