简体   繁体   中英

using babel org mode on emacs as a python data analysis environment

I've started using org-babel on emacs 25.3.1. for my initialization file and for organizing. I am using ein to run jupyter notebook and wanted to know if it is possible to use org-babel in the same way.

The ein notebook I use for data analysis using the numpy , pandas , and matplotlib python libraries, It works very well but seeing examples to similar work done with R and gnuplot on babel in org-mode I wonder if it can work for python analytics packages.

Here is a link to babel's short documentation, the introduction to literate programming with a few snippets of code in different languages.

I use Python version 3.5.4 anaconda which conveniently installs all the libraries and with anaconda-mode on emacs I have access to all functionalities, yet in babel:

#+BEGIN_SRC python :results output
import numpy
arr = np.arange(10).reshape(2, 5)
a
#+END_SRC

This code in the org file doesn't really see the anaconda installation since it uses the emacs python-mode, I think, and therefore doesn't import numpy...

I like the idea of literate programming, it might be less useful than a notebook with code cells and markdown cells but considering the customizable nature of org-mode , it can be very interesting to work in that enviornment.

EDIT starting here

I found this implementation in a previous question the answer by @bowen.li has useful code for changing the interperter to ipython and therefore have access to the missing libraries. I am still looking for ways to implement more functionality, like inline plotting with matplotlib.

I don't think anaconda has anything to do with it: your script is buggy. If I do:

#+BEGIN_SRC python :results output
import numpy as np

a = np.arange(10).reshape(2, 5)
print(a)
#+END_SRC

I get

#+RESULTS:
: [[0 1 2 3 4]
:  [5 6 7 8 9]]

You do need to load ob-python in order to use babel with python, but that's standard: you need to load ob-XXX in order to use babel with XXX in general.

John Kitchin uses python and org-mode (among many other things) extensively. You might want to visit his blog archive and browse.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM