I am working with python code, and I would like to be able to evaluate it in an emacs buffer, rather than using another terminal window. I am working with the python-mode from python.el, bundled with emacs.

This works just fine with emacs 24.3 on two different computers (windows and linux). However, I cannot get it to work on a 4rd computer with emacs 24.4: after spawning the buffer, it only shows completion candidates for an empty string (even though I didn't ask for any completion), and if I send a string, be it from a python-mode buffer or directly in the comint buffer, it just shows this list of completions again, and not the result of the command.

What's even more troubling is that according to google results, I am the only one with this issue, yet it is out-of-the-box experience!

Here are some screenshots with emacs -Q:

Bottom of the output: enter image description here

Top of the output: enter image description here

I am using emacs 24.4.1 on linux, and the problem appears with both python 2.7.9 and python 3.4.1.

Any clue?

Edit 1 Thanks to Ista's answer, I was able to check that there is nothing different in my *Messages* or in the content of variables python-shell-interpreter, python-shell-interpreter-args, python-shell-completion-setup-code, python-ffap-setup-code or python-eldoc-setup-code when compared to a working setup.

Edit 2 Thanks to a comment by Ista, I tried with a new user, and the problem didn't appear! I have tried restoring various settings to default (notably desktop-wide shortcuts), but without success for now.

Edit 3 I also tried with the ipython interpreter, the result is the same.

Edit 4 I tried starting python from eshell, shell and term (line-mode), it has the same problem: when I enter 2+2; and press RET, I see a list of completions instead of 4. term with char-mode works fine.

Overall, it looks like emacs sends a <TAB> to the inferior process whenever it tries to interact with it.

  • I recommend looking at Elpy: github.com/jorgenschaefer/elpy Follow those install instructions.
    – mankoff
    Commented Mar 8, 2015 at 17:05
  • I think we need more details, as I don't see this problem with emacs 24.4.1 (I have python 3.4.3 but would be surprised if python versions were the cause). Exactly how did you start the python interpreter? Exactly how did you send the string to be evaluated? Where can we find the other reports of this problem you mentioned?
    – Ista
    Commented Mar 8, 2015 at 17:42
  • @Ista C-c C-p (run-python) I see the output of the screenshots with just this command. Sending a string, either with C-c C-c or by typing it in the inferior buffer, only causes this output to appear again. And as far as I know, there is no other report, which is the strangest part.
    – T. Verron
    Commented Mar 8, 2015 at 18:58
  • did you try using ipython interpreter instead of the normal python interpreter? ipython's tab completion must not lead to errors!!!
    – Saravana
    Commented Mar 10, 2015 at 16:11
  • Now I did try, and sadly it didn't obey your command, it has the same problem. Overall, it's just as if my emacs sends a tab to the python buffer whenever I try to interact with it (start it or send a string).
    – T. Verron
    Commented Mar 10, 2015 at 20:10

2 Answers 2


Not an answer but posting here because it is too long for a comment.

That sounds very strange. Is there anything odd in your messages buffer after you start python? Here is what I see:

Making python-shell-interpreter local to *Python* while let-bound!
Making python-shell-interpreter-args local to *Python* while let-bound!
Sent python-shell-completion-setup-code
Sent python-ffap-setup-code
Sent python-eldoc-setup-code

and here are the contents of the mentioned variables:

python-shell-interpreter is a variable defined in `python.el'.
Its value is "python"

python-shell-interpreter-args is a variable defined in `python.el'.
Its value is "-i"

python-shell-completion-setup-code is a variable defined in `python.el'.
Its value is
    import readline, rlcompleter
except ImportError:
    def __PYTHON_EL_get_completions(text):
        return []
    def __PYTHON_EL_get_completions(text):
        completions = []
            splits = text.split()
            is_module = splits and splits[0] in ('from', 'import')
            is_ipython = getattr(
                __builtins__, '__IPYTHON__',
                getattr(__builtins__, '__IPYTHON__active', False))
            if is_module:
                from IPython.core.completerlib import module_completion
                completions = module_completion(text.strip())
            elif is_ipython and getattr(__builtins__, '__IP', None):
                completions = __IP.complete(text)
            elif is_ipython and getattr(__builtins__, 'get_ipython', None):
                completions = get_ipython().Completer.all_completions(text)
                i = 0
                while True:
                    res = readline.get_completer()(text, i)
                    if not res:
                    i += 1
        return completions"
python-ffap-setup-code is a variable defined in `python.el'.
Its value is
"def __FFAP_get_module_path(module):
        import os
        path = __import__(module).__file__
        if path[-4:] == '.pyc' and os.path.exists(path[0:-1]):
            path = path[:-1]
        return path
        return ''"

python-eldoc-setup-code is a variable defined in `python.el'.
Its value is
"def __PYDOC_get_help(obj):
        import inspect
        if hasattr(obj, 'startswith'):
            obj = eval(obj, globals())
        doc = inspect.getdoc(obj)
        if not doc and callable(obj):
            target = None
            if inspect.isclass(obj) and hasattr(obj, '__init__'):
                target = obj.__init__
                objtype = 'class'
                target = obj
                objtype = 'def'
            if target:
                args = inspect.formatargspec(
                name = obj.__name__
                doc = '{objtype} {name}{args}'.format(
                    objtype=objtype, name=name, args=args
            doc = doc.splitlines()[0]
        doc = ''
        exec('print doc')
    except SyntaxError:

Perhaps you can spot a difference between my settings and yours that might be causing the issue (these are the settings I have when starting with emacs -Q). You may also try running the code defined in python-shell-completion-setup-code, python-ffap-setup-code and python-eldoc-setup-code in python to see if they do something unexpected. Maybe you redefined one of the python functions called by them?

  • "Maybe you redefined one of the python functions called by them?" I definitely didn't redefine anything. However I will run the comparison you suggest, thanks.
    – T. Verron
    Commented Mar 8, 2015 at 20:26
  • Do the variables really look like that when you inspect them? Mine are on a single line, with \n replacing the line breaks. If I echo -e them into a file, python can load it without a problem. However, it cannot parse them if the \ns are not "de-escaped".
    – T. Verron
    Commented Mar 8, 2015 at 20:36
  • No I replaced "\n" with newlines for readability.
    – Ista
    Commented Mar 8, 2015 at 20:38
  • Then there's nothing different between my emacs settings (with `-Q) and yours. Thanks for helping me check that!
    – T. Verron
    Commented Mar 8, 2015 at 20:48
  • Does it still happen if you create and log in to a new user account?
    – Ista
    Commented Mar 8, 2015 at 21:51

Investigating all my local settings finally gave the answer.

I had in my .inputrc (settings for readline, which is used by the interactive python interpreter) the line :

Control-j: menu-complete

I have no idea what it was supposed to do, but at least commenting it out fixed it.

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.