From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Schulte Subject: Re: [babel] Setting python interpreter version on per-block or per-subtree basis Date: Fri, 25 Apr 2014 09:27:54 -0600 Message-ID: <87bnvp2zsp.fsf@gmail.com> References: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:44598) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wdi4B-0000Hm-3w for emacs-orgmode@gnu.org; Fri, 25 Apr 2014 11:29:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wdi45-00066O-D4 for emacs-orgmode@gnu.org; Fri, 25 Apr 2014 11:29:31 -0400 Received: from mail-pb0-x22a.google.com ([2607:f8b0:400e:c01::22a]:36919) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wdi45-00066B-5T for emacs-orgmode@gnu.org; Fri, 25 Apr 2014 11:29:25 -0400 Received: by mail-pb0-f42.google.com with SMTP id un15so3330285pbc.15 for ; Fri, 25 Apr 2014 08:29:23 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: William Henney Cc: emacs-org --=-=-= Content-Type: text/plain The attached patch should allow the specification of the python command through a new :python header argument. E.g., #+begin_src python :python /path/to/python2 return 1 + 2 #+end_src If someone who actually uses python could confirm that it works as expected then I'll be happy to apply it. --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-allow-specification-of-python-command-w-header-arg.patch >From d57887adc70c524199b3307b74f17ea5751450f0 Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Fri, 25 Apr 2014 09:24:04 -0600 Subject: [PATCH] allow specification of python command w/header arg Using the :python header arg. * lisp/ob-python.el (org-babel-execute:python): Locally set `org-babel-python-command' using a header argument. --- lisp/ob-python.el | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lisp/ob-python.el b/lisp/ob-python.el index baa5764..eb25609 100644 --- a/lisp/ob-python.el +++ b/lisp/ob-python.el @@ -82,6 +82,8 @@ This function is called by `org-babel-execute-src-block'." (return-val (when (and (eq result-type 'value) (not session)) (cdr (assoc :return params)))) (preamble (cdr (assoc :preamble params))) + (org-babel-python-command + (or (cdr (assoc :python params)) org-babel-python-command)) (full-body (org-babel-expand-body:generic (concat body (if return-val (format "\nreturn %s" return-val) "")) -- 1.9.2 --=-=-= Content-Type: text/plain Best, Eric William Henney writes: > Hi > > Is there an easy way to specify the python version to use for a particular > block or sub-tree? > > My use case is that I have mainly migrated to python 3, but there is still > the occasional library that has not been updated yet, so I need to fall > back to python 2.7 for some tasks. > > I can work around the problem by putting the python 2 code in a separate > org file and use > > # Local Variables: > # org-babel-python-command: "/path/to/python2" > # End: > > but keeping everything in the same file would be preferable. > > Thanks > > Will -- Eric Schulte https://cs.unm.edu/~eschulte PGP: 0x614CA05D --=-=-=--