ob-ipython introduce
ob-ipython是基于org-babel,提供了一个在org-mode下做类似jupyter-notebook体验的开发模式. 用来快速做代码尝试或一个pandas数据分析很长合适.
为什么不使用原声的jupyter呢?
- 基于browser的jupyter使用体验并不好.
按键配置和补全,snippets等等都是致命伤,这让jupyter notebook用起来更像个toy-project.
-
org-mode天生强大的功能配合ob-babel, ob-ipython. org-mode强大的文件编辑功能自不必说, 这种方式也比原生的代码里套markdown的方式更舒服. 配合上可以使用emacs所有的增强功能.
-
literal-programming的正确使用方式.
支持的特性
- 内嵌pandas, matplotlib图片和表格数据
- org-mode variable
- 导出功能export
- multi-language??
- jupyter-kernel support??
- working with a remote session??
- 在代码中打开REPL to play with.
- org literal-programming with :tang supported.
install in spacemacs
first add ob-ipython to spacemacs dotspacemacs-additional-packages
install jupyter
pip install jupyter
config ob-ipython in spacemacs `user-config`
(with-eval-after-load 'org
(add-to-list 'org-babel-load-languages '(ipython . t))
(add-to-list 'org-babel-load-languages '(rust . t))
;; 不再询问是否允许执行代码块
(setq org-confirm-babel-evaluate nil)
;; displace/update images in the buffer after I evaluate
(add-hook 'org-babel-after-execute-hook 'org-display-inline-images 'append))
add snipet for conversation
# -*- mode: snippet -*-
# name: ipython block
# key: srcip
# --
#+BEGIN_SRC ipython :session ${1::ipyfile ${2:$$(let ((temporary-file-directory "./")) (make-temp-file (concat (file-name-sans-extension (file-name-nondirectory buffer-file-name)) "-py") nil ".png"))} }:exports ${3:both} :results raw drawer
$0
#+END_SRC
use example and tips
使用maptlotlib inline来保证图片输出
%matplotlib inline
import matplotlib.pylot as plt
import numpy
plt.hist(np.random.randn(20000), bins=200)