Jupyter notebook使用


欢迎关注天下博客:http://blog.genesino.com/2017/12/jupyter/
Jupyter notebook (Ipython notebook)是集代码、结果、文档三位一体的文学化可重复程序文档。支持40多种程序语言,Python为原生语言。如果安装了Anaconda,就会自动包含。Anaconda的安装见之前的文档Linux学习 - Conda软件安装方法](http://mp.weixin.qq.com/s/A4_j8ZbyprMr1TT_wgisQQ)。

其界面如下:点击右侧的New-Python3就可以新建一个notebook。

这是一个Notebook的界面,鼠标点击即可写代码;点击run cell运行代码;按图示更改每个输入框的内容属性,选择CodeMarkdown,写完内容点击运行就可以运行代码或转换Markdown文本。

常用快捷操作

Jupyter Notebook 有两种键盘输入模式。

编辑模式,允许你往单元中键入代码或文本;这时的单元框线是绿色的。

命令模式,键盘输入运行程序命令;这时的单元框线是灰色。

Shift+Enter: 运行本单元,选中下个单元

Ctrl+Enter: 运行本单元

Alt+Enter: 运行本单元,在其下插入新单元

y:单元转入代码状态

m:单元转入markdown状态

a :在上方插入新单元

b:在下方插入新单元

x:剪切选中的单元

Shift+V:在上方粘贴单元

Jupyter小技巧

  1. 代码框输入%load sxbd.py就会加载之前写过的脚本
  2. 也可以加载在线代码 % load http://www.sxbd.com/sxbd.py
  3. 代码框输入%run progam即可运行写好的Python脚本(一般不写后缀)
  4. 代码框输入!bash command可运行bash命令
  5. %matplotlib inline嵌入matplotlib的图像
  6. %timeit python scripts评估函数的运行时间和内存使用
  7. %lsmagic列出所有的magic函数
  8. 代码框开头输入%%writefile sxbd.py即可把当前cell的命令存到对应文件

    更多Magic见http://nbviewer.jupyter.org/github/ipython/ipython/blob/1.x/examples/notebooks/Cell%20Magics.ipynb#The-cell-magics-in-IPython

Jupyter插件安装

  • 安装时先关闭Jupyter程序
  • 安装Jupyter插件管理工具 conda install -c conda-forge jupyter_contrib_nbextensions
  • 激活Jupyter插件管理工具 jupyter nbextensions_configurator enable --user
  • 安装jupyter-vim-binding

    
    # You may need the following to create the directoy
    
    
    # 一般是家目录下的 ~/.local/share/jupyter/nbextensions
    
    mkdir -p $(jupyter --data-dir)/nbextensions
    
    # Now clone the repository
    
    cd $(jupyter --data-dir)/nbextensions
    git clone https://github.com/lambdalisue/jupyter-vim-binding vim_binding
    chmod -R go-w vim_binding
  • 激活jupyter-vim-binding

    启动Jupyter notebook, 进入http://localhost:8888/nbextensions/,激活插件

    每个插件点击可查看其功能描述,使用方式,批量gif演示插件功能。

服务器端使用

jupyter notebook --no-browser -y即可启动,访问IP:8888即可。

Jupyter 主题

安装主题控制插件

pip install jupyterthemes

修改主题,具体参数看jt命令解释 https://github.com/dunovank/jupyter-themes

jt -fs 200 -tfs 17 -t grade3 -f roboto -cellw 88% -dfs 12 -ofs 15 -T

JupyterHub 多用户

JupyterHub安装 (centos 7)

# Jupyer 依赖npm
yum install epel-release
npm -v # 测试npm是否安装好
# 安装nodejs8 
curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -
node -v # 测试nodejs是否安装好
# 安装JupyterHub
npm install -g configurable-http-proxy
pip3 install jupyterhub 

References

  1. https://github.com/ipython-contrib/jupyter_contrib_nbextensions#installation
  2. https://github.com/lambdalisue/jupyter-vim-binding/wiki/Installation
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

生信宝典

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值