1 简介
简而言之,Jupyter Notebook是以网页的形式打开,可以在网页页面中直接编写代码和运行代码,代码的运行结果也会直接在代码块下显示。如在编程过程中需要编写说明文档,可在同一个页面中直接编写,便于作及时的说明和解释。
2 安装
在安装anaconda的前提下(只要从官网下载安装包一键安装即可),打开anaconda prompt,输入如下命令:
conda install jupyter notebook
3 启动
在anaconda终端中输入如下命令,会自动在浏览器中打开网页
jupyter notebook
4 设置Jupyter Notebook文件存放位置
查看配置文件路径:
jupyter notebook --generate-config
找到配置文件的路径,编辑jupyter_notebook_config.py
进入配置文件后查找关键词c.NotebookApp.notebook_dir
对该行取消注释,并加入新路径
c.NotebookApp.port = 8888 #修改端口
5 关联conda环境和包
anaconda3自带nb_conda包,这个包可以在jupyter中对conda环境进行操作,可以点击conda进行包管理
如需进行虚拟环境的切换,则要安装ipykernel
conda install ipykernel
将已有的虚拟环境导入值kernel中:
python -m ipykernel install --user --name 环境名称 --display-name "Python (环境名称)"
这样在jupyter中新建python就可以选择不同的虚拟环境了
6.Jupyter 插件安装指南
pip install jupyter_nbextensions_configurator
pip install jupyter_contrib_nbextensions
jupyter nbextensions_configurator enable --user
jupyter contrib nbextension install --user
然后就会多看到一个 Nbextensions;
选择你感兴趣的插件。
推荐:
- code prettify
- Table of Contents :自动生成目录插件,如果在 jupyter notebook 中使用了markdown对程序进行了解释和说明的话,那么安装这个插件以后,会自动在大纲视图,对于阅读程序使用,强力推荐
- contrib_nbextensions…
- nbextensions dashboard tab
- printview
- table_beautifier
- Nbextensions edit menu item
- Variable Inspector :这是一个查看变量的插件,类似于 Matlab 和 R studio 的工作空间,可以查看变量名、类型,大小,形状和值。其中变量的 shape (形状)这个参数在进行矩阵运算时,十分实用,并且这个窗口还可以调节大小,排序等功能,十分推荐
- ExcecuteTime: 查看代码执行时间,这个插件会代码模块最后计算该模块的计算时间和运行结束时间,美观实用
- Hinterland:勾选此插件为代码单元格中的每次按键启用“代码自动补全”菜单,而不是仅用Tab键时启用
- Codefolding:这个扩展将代码折叠功能从CodeMirror添加到codecell。在编辑模式下,单击边距中的三角形(codecell的左边缘)或键入代码折叠热键(默认为Alt+F),折叠代码。在命令模式下,折叠热键与编解码器的第一行有关
7. jupyter选择conda环境
- conda install ipykernel
- source activate test # test为要激活的环境
- python -m ipykernel install --user --name test --display-name “Python test”
打开jupyter可看到多了一个python test环境