Whenever I send the a Python buffer to the interpreter via C-x C-l it prints the file eval call as shown below. While it does print the correct output, it's a bit annoying to see it every time and I'd like help getting rid of that behavior.

My question is, How to get rid of the __PYTHON_EL_eval_file("/Users/user/Documents/Sandbox/Python/test.py", "", False) that prints in the interpreter when the file is sent with C-x C-l?


def main():
    print("Hello World!")

if __name__ == "__main__":


>>> __PYTHON_EL_eval_file("/Users/user/Documents/Sandbox/Python/test.py", "", False)
Hello World!

I'm running on MacOS Ventura 13.2.1 (22D68), using Emacs from EmacsforOSX.

Here's the output of running M-x elpy-config.

Elpy Configuration

Emacs.............: 28.2
Elpy..............: 1.35.0
Virtualenv........: None
Interactive Python: python3 3.11.2 (/Library/Frameworks/Python.framework/Versions/3.11/bin/python3)
RPC virtualenv....: rpc-venv (/Users/user/.config/emacs/elpy/rpc-venv)
 Python...........: python3 3.8.2 (/Users/user/.config/emacs/elpy/rpc-venv/bin/python3)
 Jedi.............: 0.18.2
 Autopep8.........: 2.0.2
 Yapf.............: 0.32.0
 Black............: Not found (23.1.0 available)
Syntax checker....: flake8 (/Library/Frameworks/Python.framework/Versions/3.8/bin/flake8)


You have not activated a virtual env. It is not mandatory but often a good idea
to work inside a virtual env. You can use `M-x pyvenv-activate` or `M-x
pyvenv-workon` to activate one.

The directory ~/.local/bin/ is not in your PATH. As there is no active
virtualenv, installing Python packages locally will place executables in that
directory, so Emacs won't find them. If you are missing some commands, do add
this directory to your PATH -- and then do `elpy-rpc-restart'.


`Raised' text indicates buttons; type RET or click mouse-1 on a button to
invoke its action.  Invoke [+] to expand a group, and [-] to collapse an
expanded group.  Invoke the [Group], [Face], and [Option] buttons below to edit
that item in another window.

[+]-- Group Elpy
[+]-- Group Python
[+]-- Group Virtual Environments (Pyvenv)
[+]-- Group Completion (Company)
[+]-- Group Call Signatures (ElDoc)
[+]-- Group Inline Errors (Flymake)
[+]-- Group Code folding (hideshow)
[+]-- Group Snippets (YASnippet)
[+]-- Group Directory Grep (rgrep)
[+]-- Group Search as You Type (ido)
[+]-- Group Django extension
[+]-- Group Autodoc extension

And the Python-specific parts of my init.el

(setq elpy-rpc-python-command "python3")
(setq python-shell-interpreter "python3")
(setq python-shell-completion-native-disabled-interpreters '("python3"))
  • 2
    What's the question?
    – Drew
    Commented Mar 27, 2023 at 1:58
  • How to get rid of the __PYTHON_EL_eval_file("/Users/user/Documents/Sandbox/Python/test.py", "", False) that prints in the interpreter when the file is sent with C-x C-l
    – Ricardo
    Commented Mar 27, 2023 at 3:08
  • 1
    Put that question in the question you posted somewhere, please. Q&A need to stand on their own; comments can be deleted any time, and they're not searchable. Thx.
    – Drew
    Commented Mar 27, 2023 at 14:19
  • 1
    Done. And thanks for prompting me to do that.
    – Ricardo
    Commented Mar 27, 2023 at 16:26

6 Answers 6


This is a hack, but it worked for me:

(defun python-comint-filter (output)
  (let* ((regexp "^.*__PYTHON_EL_\\(.*\\)\\(.*\\)[[:space:]]*$")
         (lines (split-string output "\n"))
         (filtered-lines (remove-if (lambda (line)
                                      (or (string-match-p regexp line)
                                          (string-match-p "^\\s-*$" line))) 

    (if (equal (length lines) (length filtered-lines))
      (mapconcat 'identity filtered-lines "\n"))))


(add-hook 'comint-preoutput-filter-functions 'python-comint-filter)


This is a modified version of guibor's answer. It does the same thing but with basic Elisp:

(defun python-comint-filter (output)
  (replace-regexp-in-string "__PYTHON_EL_eval.+\n" "" output))
(add-to-list 'comint-preoutput-filter-functions #'python-comint-filter)

If, like me, you are getting the same string in the echo area when using Eldoc, you can also add this to your init.el:

(defun python-eldoc-filter (orig-fun string)
  (let ((clean (if (stringp string) (replace-regexp-in-string "\n__PYTHON_EL_eval.+" "" string) string)))
    (funcall orig-fun clean)))
(advice-add 'eldoc--message :around #'python-eldoc-filter)

I'm having the same issue. However, this problem only occurs with Python downloaded and installed from https://www.python.org

The issue can be fixed when I install Python with macports. I installed Python like this, maybe it can help you.

sudo port install python311
sudo port install gnureadline

# if you need to use tkinter
sudo port install tk +quartz
sudo port install py311-tkinter

  • I unfortunately do not use macports. I did learn that this seems to be an issue with Elpy no longer being maintained.
    – Ricardo
    Commented May 28, 2023 at 21:00

Happened to me on Homebrew's Python 3.11. The solution was to install it via pyenv, and set it to be the global interpreter.You'll have to have pyenv's bin path recognized by Emacs (if you're on Doom you have to run doom env).


Yes, that’s what python-shell-send-file does. It sends code to be evaluated in the python repl that will cause the named file to be loaded and evaluated. The code that accomplishes this is bundled up into a pthon function called __PYTHON_EL_eval_file. This function’s name was chosen specifically so that it is unlikely to conflict with any functions that are part of the code you are writing.

You could use python-shell-send-buffer instead, if you want to paste the whole buffer contents into the repl.

  • Wait, so you're saying this is expected behavior? When I use python-shell-send-buffer it now prints __PYTHON_EL_eval_file("/Users/user/Documents/Sandbox/Python/test.py", "/var/folders/62/pg1510rs0ml16dptw6mnnw4r0000gn/T/pyzj0KWS", True) in the interpreter, along with parts of the buffer.
    – Ricardo
    Commented Mar 27, 2023 at 1:07
  • Yes, this is the expected behavior.
    – db48x
    Commented Mar 27, 2023 at 1:08
  • 1
    That seems strange. I remember using it before and it not printing the function call and just evaluating the file. Is this new behavior?
    – Ricardo
    Commented Mar 27, 2023 at 1:15
  • 1
    I haven’t used it in years, but it is my understanding that it always shows you the code it runs in the REPL. Surely it would be more confusing if it didn’t.
    – db48x
    Commented Mar 27, 2023 at 1:59
  • 3
    I have the same issue on Mac OS X, and I remember that in the past I did not have this printing out every time I sent something to the shell - this is clearly not the expected behaviour.
    – guibor
    Commented May 1, 2023 at 17:32

This same issue arose for me when I installed py-python-lsp-server (and python-lsp-server_select) using MacPorts and didn't select both that and python3.10 (also installed with MacPorts) using:

sudo port select --set python python310

sudo port select --set python-lsp-server py310-pylsp

I did this, ran doom sync, then restarted emacs, and the issue was gone.

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.