emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Eric Schulte <schulte.eric@gmail.com>
To: William Henney <whenney@gmail.com>
Cc: emacs-org <emacs-orgmode@gnu.org>
Subject: Re: [babel] Setting python interpreter version on per-block or per-subtree basis
Date: Fri, 25 Apr 2014 09:27:54 -0600	[thread overview]
Message-ID: <87bnvp2zsp.fsf@gmail.com> (raw)
In-Reply-To: CAKchnZOham41L2jzWbynFk3oQyrWcw6vUGduya2c3x3ZHVJQDw@mail.gmail.com

[-- Attachment #1: Type: text/plain, Size: 298 bytes --]

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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-allow-specification-of-python-command-w-header-arg.patch --]
[-- Type: text/x-diff, Size: 1022 bytes --]

From d57887adc70c524199b3307b74f17ea5751450f0 Mon Sep 17 00:00:00 2001
From: Eric Schulte <schulte.eric@gmail.com>
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


[-- Attachment #3: Type: text/plain, Size: 677 bytes --]


Best,
Eric

William Henney <whenney@gmail.com> 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

  parent reply	other threads:[~2014-04-25 15:29 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-24 17:04 [babel] Setting python interpreter version on per-block or per-subtree basis William Henney
2014-04-25  1:59 ` Sacha Chua
2014-04-25  9:00 ` Ian Barton
2014-04-25 15:27 ` Eric Schulte [this message]
2014-04-25 16:29   ` William Henney
2014-04-25 18:04     ` Eric Schulte

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87bnvp2zsp.fsf@gmail.com \
    --to=schulte.eric@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=whenney@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).