On Emacs 29, Python 3.11.3, IPython 8.13.2

A strange behavior seems to have recently started. When opening a python shell with run-python and then python-shell-send-buffer or python-shell-send-file Tab completion inserts the command that is sent to the shell to send the buffer or file. Something like:

__PYTHON_EL_eval_file("/var/folders/bq/8rm29p3528bggkl1dy36h4mh0000gn/T/pySXmI6k", "/var/folders/bq/8rm29p3528bggkl1dy36h4mh0000gn/T/pySXmI6k", True))

completion-at-point-fuction is set to (python-shell-completion-at-point comint-completion-at-point t).

This happens with python-mode or python.el and using both python3 or ipython3 for the inferior python mode.

How can I prevent this from happening?

See below:

Before pressing tab: enter image description here

After pressing tab: enter image description here

Interestingly, it does complete "Image". But it adds the file load command before the completed text.

  • 1
    Same problem here with, didnt find a fix yet. Commented Oct 9, 2023 at 0:15
  • Perhaps we can debug this together. What does your Python dev environment consist of? For me, it's lsp-mode with pyright, python-mode, pyvenv. For completions I use company and company-box.
    – Metropolis
    Commented Oct 10, 2023 at 15:17

1 Answer 1


I found the following workaround. I wish I better understood where this problem stems from though.

(defun my-python-completion-filter (completions)
  "Filter out the unwanted '__PYTHON_EL' from COMPLETIONS."
  (cl-remove-if (lambda (completion) (string-match-p "__PYTHON_EL" completion))

(advice-add 'python-shell-completion-get-completions :filter-return #'my-python-completion-filter)
  • This is a decent work-around; just remove the weird bit from the completions list. I will give it a try.
    – Metropolis
    Commented Mar 10 at 16:31
  • Thanks, let me know if it worked or if you found anything better
    – guibor
    Commented May 20 at 12:13

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.