gregsexton/ob-ipython

Pre-initiate kernel and consol

Closed this issue · 8 comments

Xparx commented

Hi,

I'm wondering if it's possible to initiate a kernel and console in emacs before evaluating any src blocks.
run-python will of course start python but not a ipython notebook kernel.

I have the same wonder as well. To change command python-shell-interpretre 'ipython' to '~/anaconda/bin/ipython' in 'the spacemacs/python-setup-shell' function in the file '.emacs.d/layers/+lang/python/funcs.el' works for me well.

I've experimented with doing something like this as a file-local variable in ob-ipython notebooks

# Local Variables:
# eval: (progn (pyvenv-workon "notebook") (quote (org-sbe ipython-init)))
# End:

where ipython-init is a library of babel block that does some basic imports. It's kind of clunky though.

Edit: I should note that this soometimes runs into the old "Trying to parse HTTP response" error.

Xparx commented

@tbrandseg That solution looks interesting. Will try when I get hold of my computer.

Xparx commented

@tbrandseg I'm looking in to your suggestion and it looks really interesting. But I need some help with the actual initiation in the eval: line. When/how is this line executed. I have tried opening the file but it does not seem to do anything. I also tried C-c C-c in this header but it does not work.

@Xparx Did you add it with M-x add-file-local-variable? That should put things in the right place, and emacs should ask you whether you want to evaluate the file local variables next time you open the file.

@Xparx Also I just realized there's a mistake in my post above - the org-sbe expression should not be quoted. So what you should do, assuming you have a block that does your initialization called python-init, is

M-x add-file-local-variable RET (org-sbe python-init) RET

Then save and re-open the file and you should be good to go.

Xparx commented

@tbrantseg I finally tested it with success. Turns out I had the variable (setq enable-local-variables :safe) which made it so the local variable wasn't executing. Not sure what the best policy is here, to have it ask me or to turn it of so it always executes. But this solutions seems to work well now.

Xparx commented

In the latest ob-ipython it looks like I can just run C-c C-v C-z in a code block to start up a kernel.