From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ista Zahn Subject: Re: python sessions Date: Wed, 20 Mar 2013 08:54:31 -0400 Message-ID: References: <16146.1363748839@alphaville> <51495ADB.7020609@easy-emacs.de> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([208.118.235.92]:36545) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UIIrB-0000ad-65 for emacs-orgmode@gnu.org; Wed, 20 Mar 2013 09:15:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UIIr8-0004Fd-6A for emacs-orgmode@gnu.org; Wed, 20 Mar 2013 09:15:05 -0400 Received: from mail-da0-x22a.google.com ([2607:f8b0:400e:c00::22a]:36291) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UIIXc-0005yf-Mv for emacs-orgmode@gnu.org; Wed, 20 Mar 2013 08:54:52 -0400 Received: by mail-da0-f42.google.com with SMTP id n15so976141dad.15 for ; Wed, 20 Mar 2013 05:54:51 -0700 (PDT) In-Reply-To: <51495ADB.7020609@easy-emacs.de> 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: =?UTF-8?Q?Andreas_R=C3=B6hler?= Cc: emacs-orgmode@gnu.org On Wed, Mar 20, 2013 at 2:44 AM, Andreas R=C3=B6hler wrote: > Am 20.03.2013 04:07, schrieb Nick Dokos: > >> John Hendy wrote: >> >>> On Tue, Mar 19, 2013 at 4:40 PM, Gary Oberbrunner >>> 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: >>>> >>>> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >>>> >>>> * My Document >>>> #+BEGIN_SRC python :exports results :results output :session >>>> def foo(x): >>>> return x+1 >>>> print "hi" >>>> #+END_SRC >>>> >>>> #+RESULTS: >>>> : hi >>>> >>>> #+BEGIN_SRC python :exports results :results output :session >>>> print foo(100) >>>> print "bye" >>>> #+END_SRC >>>> >>>> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D >>>> >>>> In session mode, shouldn't foo be defined in the second python block? >>>> When >>>> I export this, I get "NameError: name 'foo' is not defined" >>>> >>>> I may be doing something wrong, because if I name my python session, I >>>> never >>>> see a buffer of that name, and I expected to. Any help? >>>> >>>> -- >>>> Gary >>> >>> >>> You should probably post your babel configuration from .emacs. This >>> works for me (mostly). I'm using python 3.3 and so the print function >>> has changed to requiring parentheses. I can switch to a buffer called >>> *Python*, however, and =3Dprint("hi")=3D works fine. >>> >>> If I change to =3Dprint(foo(100))=3D, I get 101 in the #+RESULTS block. >>> >> >> I don't - I get the same error as Gary. >> >> And looking at the code of org-babel-python-initiate-session-by-key, >> I don't understand how it's supposed to work: python-buffer is nil >> to begin with; the cond takes the first branch and starts a python >> session. >> When we come to >> >> (setq org-babel-python-buffers >> (cons (cons session python-buffer) >> (assq-delete-all session org-babel-python-buffers))) >> >> python-buffer is still nil, so we are cooked. >> >> Maybe python-buffer was set as a side-effect of run-python in earlier >> versions of emacs? If so, it does not seem to be the case now. >> >> Nick >> >> Org-mode version 8.0-pre (release_8.0-pre-144-g855dcf.dirty @ >> /home/nick/elisp/org-mode/lisp/) >> GNU Emacs 24.3.50.2 (x86_64-unknown-linux-gnu, GTK+ Version 2.24.4) of >> 2012-12-29 on alphaville >> >> > > AFAIU :session is broken, because Python shell as opened by run-python or > py-shell isn't used by ob-babel. > Seems ob-babel sends it's code w/ an own shell command, thus opening a ne= w > python shell internally every time. > > Did :session ever work? Then I might be wrong with this comment. Not only did it work, it currently works for me. I seem to remember bad interaction with python modes other than the one shipped with emacs. In my .emacs I have ;; Python ;; there are several modes. Currently using https://github.com/fgallina/python.el ;; hopefully oneday a glorious default python mode will be shipped with emacs and we won't need this anymore. ;; (add-to-list 'load-path "~/.emacs.d/izahn") ;; (require 'python) ;; (setq ;; python-shell-interpreter "ipython" ;; python-shell-interpreter-args "" ;; python-shell-prompt-regexp "In \\[[0-9]+\\]: " ;; python-shell-prompt-output-regexp "Out\\[[0-9]+\\]: " ;; python-shell-completion-setup-code ;; "from IPython.core.completerlib import module_completion" ;; python-shell-completion-module-string-code ;; "';'.join(module_completion('''%s'''))\n" ;; python-shell-completion-string-code ;; "';'.join(get_ipython().Completer.all_completions('''%s'''))\n") ;; (require 'python-mode) ;; ;; python auto completion (require 'ac-python) All the python-mode and ipython mode stuff is commented out partly because it did not play nice with org-mode. Using the default python mode works for me. So, for those of you who are finding that this is not working, what python mode are you using? Best, Ista > > Andreas > > >