Jupyter Notebook 快速入门

一、 Jupyter NoteBook的安装

新版本Anaconda自带Jupyter

二、 更改Jupyter notebook的工作空间

桌面新建快捷方式,修改目标,红色部分是添加的新工作目录

C:\Anaconda2\python.exe C:\Anaconda2\cwp.py C:\Anaconda2 "C:/Anaconda2/python.exe" "C:/Anaconda2/Scripts/jupyter-notebook-script.py" E:\Jupyter %USERPROFILE%

 

三、Jupyter的各种快捷键

按下H

四、Jupyter Notebook如何导入代码

即导入代码到jupyter notebook的cell中

4.1 将本地的.py文件load到jupyter的一个cell中

问题背景:有一个test.py文件,需要将其载入到jupyter的一个cell中 
test.py内容如下:

import caffe
SolverName = "/root/workspace"
sovler = caffe.AdamSolver(SolverName)

方法步骤: 
(1)在需要导入该段代码的cell中输入

%load test.py #test.py #是当前路径下的一个python文件

(2)运行该cell 
利用快捷键“Shift+Enter”,可以看到如下结果: 
这里写图片描述

(3)可以看到,运行后,%load test.py被自动加入了注释符号#,test.py中的所有代码都被load到了当前的cell中

五、Jupyter运行python文件

利用jupyter的cell是可以运行python文件的,即在cell中运行如下代码:

%run file.py

file.py为要运行的python程序,结果会显示在该cell中 
这里写图片描述
这里写图片描述

六、Jupyter中的Markdown

参考1 
Markdown 语法手册 (完整整理版)参考

6.1 在jupyter中设置link,需要设置两部分:

要跳到的位置(the destination) 
需要在要跳转到的位置添加下面语句:

<a id='the_destination'></a>

这里的id取值任意赋值,下面在添加链接时要用

需要添加链接的文字(an internal hyperlink to the destination),即点击该处可以跳转到the destination,在需要添加链接的文字后面加入:

[需要添加连接的文字](#the_destination)

 

 

下面是一个例子: 
源码: 
这里写图片描述
效果图: 
这里写图片描述

七.其他

7.1 使用Matplotlib绘图

在Jupyter Notebook中,如果使用Matplotlib绘图,有时是弹不出图像框的,此时,可以在开头加入

%matplotlib inline

 7.2 主题更换

pip install --upgrade jupyterthemes

然后可以查看所有可用的主题:

jt -l

可以用下面命令选择要用的主题:

jt -t grade3 -cellw 1366  白底
jt -t solarizedl -cellw 1366  黄底
jt -t monokai -cellw 1366   黑底

如果要恢复默认:

jt -r

 7.3 Markdown颜色

<font color='green'>text</font>

 7.4 Markdown插入网页链接

[Dogs vs. Cats Redux: Kernels Edition](https://www.kaggle.com/c/dogs-vs-cats-redux-kernels-edition)

 

 八、Jupyter notebook中设定Kernel为Python2和Python3

添加python3的kernel,在Windows下cmd中设置: 

先激活python3 activate py3  然后

ipython3 kernelspec install-self

九、jupyter密码设置

jupyter notebook --generate -config
jupyter notebook password

 十、模块折叠

安装nbextensions

pip install jupyter_contrib_nbextensions
jupyter contrib nbextension install --user

安装nbextensions_configurator

pip install jupyter_nbextensions_configurator
jupyter nbextensions_configurator enable --user

勾选Hinterland即启用了代码自动补全

Collapsible Headings 标题折叠

打开Jupyter Notebook,在它的(新增的)Nbextensions标签下勾选“Table of Contents(2)”  自动加目录

十一、jupyter notebook 中 python 环境选择

一般安装了anaconda会自带jupyter notebook,但是这样启动的notebook运行的是base环境,当我们创建其他虚拟环境时启动notebook是还是运行base环境。

想指定notebook的运行环境需要

conda install nb_conda

posted @ 2017-08-21 09:22  xuanyuyt  阅读(1494)  评论(0编辑  收藏  举报