#+begin_src python :session :results output

With org-babel-execute-src-block command, the result is:

: __PYTHON_EL_eval("try:\n    with open('/var/folders/hh/lnftkrwn1tv9b63ptnphj_gm0000gp/T/babel-ww4KL0/python-AICyg8') as __org_babel_python_tmpfile:\n        exec(compile(__org_babel_python_tmpfile.read(), __org_babel_python_tmpfile.name, 'exec'))\nexcept:\n    raise\nfinally:\n    print('

not "yes".

:results value is behaved as expected.

Error message:

error in process filter: sort: Wrong type argument: stringp, (\, "python")
error in process filter: Wrong type argument: stringp, (\, "python")
Can’t guess python-indent-offset, using defaults: 4


GNU Emacs 28.1 (build 1, x86_64-apple-darwin19.6.0, Carbon Version 162 AppKit 1894.6)
 of 2022-04-28
org mode 9.5.3

Update: I find the error gone when I use python 3.9 instead of python 3.7. I do not understand the link between the issue and version of python, but it does fix the issue.

  • Which command was used? M-x org-babel-execute-src-block RET prints "yes" with GNU Emacs 28.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 2.24.32, cairo version 1.16.0) Commented Jun 19, 2022 at 6:10
  • @AndreasRöhler org-babel-execute-src-block
    – Tokubara
    Commented Jun 19, 2022 at 8:17
  • Might be a bug. Please consider filing your question a <[email protected]> Commented Jun 20, 2022 at 9:19

2 Answers 2


I just ran into the same issue, and I bugged someone much smarter than me about it -- her conclusion after some debugging was that it seems like this basically boils down to the Python that comes with MacOS not being compiled with readline support. This could be seen by opening a python shell in emacs, and entering 1, and seeing that the input is echoed in addition to being output.

We switched to using a different python installation (specifically the one that comes with nix) and this made the issue go away. (She says that ones that come with homebrew / macports would also work; apparently it's well-known that the python version that ships with MacOS has these kinds of problems.)

Slightly unsatisfying + seems like black magic to me, but it's working now! :)


I came to this question seeing the same error. Eventually I discovered how python sessions use buffers and how to inspect what went wrong from this answer.

If you don't specify a :session name, the default buffer is named *Python*. To continue using that session you can:

  • switch to the buffer and inspect what may have gone wrong before this block was called and fix it up,
  • call reset on the first line of the block, or
  • use a new session name.

There may be other workarounds, including killing the session buffer.

I expect this would work on first try:

#+begin_src python :session xyzzy :results output

Unfortunately I've been unable to replicate the error since resolving it, but that would be helpful if this is considered a bug to fix.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.