I was able to reproduce the error. I started emacs without my init file (emacs -q) and then ,---- | (add-to-list 'load-path "~/code/elisp/org-mode/lisp") | (require 'ob-python) | (org-babel-do-load-languages 'org-babel-load-languages `((python . t))) `---- in scratch, and then ran your test. I got the same errors you described. I redid the test but loaded the lastest org-mode and there was no error. This means you probably don't need to debug this. It has been fixed in the latest version, but the fix hasn't been updated in the elpa package yet. you can either wait for the next release or pull the latest code from the repo. On Mon, Jul 6, 2020 at 3:18 PM Philip Blagoveschensky wrote: > Hi Ian, > > >Do you have the same issue if you aren't using a session? > > If I run the following code block (this time I am using python 3, so > there are parens in the print line) > > #+begin_src python > def foobar(): > for i in range(5): > pass > print("hello world") > return 3 > > return foobar() > #+end_src > > I get > > #+RESULTS: > : 3 > > so I know it worked fine. > > But if I add session like this: > > #+begin_src python :session bug_report > def foobar(): > for i in range(5): > pass > print("hello world") > return 3 > > return foobar() > #+end_src > > then in *bug_report* I get > > >>> def foobar(): > ... for i in range(5): > ... pass > ... > >>> print("hello world") > File "", line 1 > print("hello world") > ^ > IndentationError: unexpected indent > return 3 > >>> > File "", line 1 > return 3 > ^ > IndentationError: unexpected indent > >>> return foobar() > >>> > File "", line 1 > SyntaxError: 'return' outside function > >>> open('/tmp/babel-D0mRnD/python-CJ6UtT', 'w').write(str(_)) > >>> > 20 > >>> > >>> 'org_babel_python_eoe' > >>> 'org_babel_python_eoe' > >>> > > >Are you using tabs or spaces? > > I used spaces. 4 spaces per indentation level, to be exact. > > Also, FYI, as it might be relevant information, the shell buffer > contents I posted above happen if the session has been created > previously. If, instead, this is the first time I run some code in this > session, then I also get another error - NameError (see below). Below > you can see the contents of *bug_report* buffer if I run this code cell > in a not-yet-existing session. > > def foobar(): > Python 3.8.2 | packaged by conda-forge | (default, Mar 5 2020, 17:11:00) > [GCC 7.3.0] on linux > Type "help", "copyright", "credits" or "license" for more information. > >>> ... for i in range(5): > ... pass > ... > >>> print("hello world") > File "", line 1 > print("hello world") > ^ > IndentationError: unexpected indent return 3 > > >>> > File "", line 1 > return 3 > ^ > IndentationError: unexpected indent > >>> return foobar() > >>> > File "", line 1 > SyntaxError: 'return' outside function > >>> open('/tmp/babel-D0mRnD/python-MsDjEk', 'w').write(str(_)) > >>> > Traceback (most recent call last): > File "", line 1, in > NameError: name '_' is not defined > >>> > >>> 'org_babel_python_eoe' > >>> 'org_babel_python_eoe' > >>> > > If you have a suggestion on how to debug this, feel free to tell. >