emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] python sessions


From: John Hendy
Subject: Re: [O] python sessions
Date: Wed, 20 Mar 2013 10:38:32 -0500

On Wed, Mar 20, 2013 at 2:08 AM, Andreas Röhler
<address@hidden> wrote:
> Am 20.03.2013 01:04, schrieb John Hendy:
>
>> On Tue, Mar 19, 2013 at 4:40 PM, Gary Oberbrunner <address@hidden>
>> wrote:
>>>
>>> I must be failing to understand something.  I'm running Emacs 24.3 on
>>> Windows, with latest trunk org-mode.  I can't get python functions to
>>> persist across blocks in session mode.  Here's my foo.org:

<snip>

>> You should probably post your babel configuration from .emacs. This
>> works for me (mostly). I'm using python 3.3
>
>
> Hi John,
>
> let's point out though that matter is not at stake.
> As the OP got output, system Python must be a 2...
>

True, which is why I clarified my version. The foo() command still
worked for me; I simply had issues due to print() syntax changes
between 2 -> 3. So... I've tried to eliminate this and retried today
with the following process (note setting the python command to
"python2"):

- Start emacs with `emacs -q`

- M-x load-file ~/Desktop/minimal-config

#+begin_src minimal-config

;; load path
(add-to-list 'load-path "~/.elisp/org.git/lisp/")

;; setup babel languages
(org-babel-do-load-languages
 'org-babel-load-languages
 '((python .t )))
(setq org-babel-python-command "python2")

#+end_src

- For reference
$ python2 --version
Python 2.7.3

On first I get a syntax error executing the first block:

#+RESULTS:
: first
: ... ... ...   File "<stdin>", line 4
:     print "end first"
:         ^
: SyntaxError: invalid syntax

On a whim, I simply inserted a newline, and it worked. Here is the
full file with my executed results (C-c C-c on each block):

#+begin_src orgmode file

* My Document

The first block says:
#+BEGIN_SRC python :exports results :results output :session *PyFoo*
print "first"
def foo(x):
  print "In foo(%s)"%x
  return x+1

print "end first"
#+END_SRC

#+RESULTS:
: first
: ... ... ... >>> end first

The result is:
#+BEGIN_SRC python :exports results :results output :session *PyFoo*
print "hello"
print foo(100)
print "bye"
#+END_SRC

#+RESULTS:
: hello
: In foo(100)
: 101
: bye

#+end_src orgmode file

*Note:* I do not get a *PyFoo* session, only a *Python* buffer. When I
got to kill emacs, here is the session info asking me if I want to
kill the running buffer process:

Python          run     *Python*        /dev/pts/2   python2 -i -c import sys; 
sys.path.remove('')


So, seems to work for me. This is on Arch Linux:

- uname -a
Linux hostname 3.8.3-2-ARCH #1 SMP PREEMPT Sun Mar 17 13:04:22 CET
2013 x86_64 GNU/Linux

- emacs --version
GNU Emacs 24.2.1

- M-x org-version
Org-mode version 8.0-pre (release_8.0-pre-146-g73fe0a @
/home/jwhendy/.elisp/org.git/lisp/)


Best regards,
John


> Best,
>
> Andreas
>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]