4

On Emacs 25.2 and Python 3.5 on an Centos-like Oracle Linux I have the issue that invoking a python shell gives me no completion. To reproduce, start

$ emacs -Q --eval '(setq python-shell-interpreter "python3")'

then execute

M-x run-python

This produces the warning

Warning (python): Your ‘python-shell-interpreter’ doesn’t seem to support readline, yet ‘python-shell-completion-native’ was t and "python3" is not part of the ‘python-shell-completion-native-disabled-interpreters’ list.  Native completions have been disabled locally.

It is the same problem as Your ‘python-shell-interpreter’ doesn’t seem to support readline, but:

1) I am already on Emacs version 25.2, so the fixfrom one answer does not help (because 25.2 contains the proposed fix).

2) I am on bash 4.1 and have no ~/.inputrc file, so the fix from the other answer doesn't help either.

How can I fix this?

Update:

On my MacOS machine the initialisation works correctly. However on MacOS I use Emacs 25.3. Therefore I installed 25.3 (from source ) on the Oracle Linux system, too - the Python completion still fails, because of same above mentioned issue!

halloleo
  • 1,215
  • 9
  • 23
  • What do you get from `import readline; print (readline.__doc__)` at a `python3` shell? Also try the tests I posted [here](https://debbugs.gnu.org/cgi/bugreport.cgi?bug=25753#29) and [here](https://debbugs.gnu.org/cgi/bugreport.cgi?bug=25753#35). – npostavs Feb 16 '18 at 11:59
  • @npostavs I get an `ImportError`. On Centos (not Windows)! Appears as rather strange to me... – halloleo Feb 16 '18 at 13:00
  • Huh. That means your python lacks the readline library for some reason. AFAIK, since it's listed at https://docs.python.org/3/library/readline.html, it should come installed by default... – npostavs Feb 16 '18 at 13:52
  • A web search turns up [pyenv/pyenv#111: Build Failure on Centos 6.5: ImportError: No module named readline](https://github.com/pyenv/pyenv/issues/111), although the resolution doesn't sound widely applicable. – npostavs Feb 16 '18 at 13:59
  • @npostavs I have upgraded to Emacs 25.3 - but have still the same issue on Linux. :-( (See my update in the question.) – halloleo Feb 19 '18 at 05:34
  • Emacs 25.3 is identical to 25.2 except for a security fix for [Bug#28350 "CVE-2017-14482: enriched.el code execution"](https://debbugs.gnu.org/cgi/bugreport.cgi?bug=28350). Maybe the fix is to install the python readline module? (I still don't understand why you don't have it though) – npostavs Feb 19 '18 at 12:23
  • @npostavs pip-installing `gnureadline` did the job! Thanks for all the pointers! Do you want to put this in an answer? (ps: None of the admin-installed Pythons (2.7,3.4,3.5 and now 3.6) have the readline module. The Distro-Python 2.6 does have it though.) – halloleo Feb 20 '18 at 05:45

1 Answers1

3

The native completion mechanism depends on the gnureadline python module. You can check if it's present by executing

import readline
print(readline.__doc__)

at a python shell. The message

ImportError: No module named readline

indicates it's missing. It can be installed with pip install gnureadline. When it's correctly installed, the above code should print:

Importing this module enables command line editing using GNU readline.

The readline module might be missing on Oracle Linux for Python versions which are installed from source.

halloleo
  • 1,215
  • 9
  • 23
npostavs
  • 9,033
  • 1
  • 21
  • 53
  • 2
    I'm getting the message saying readline is correctly installed, but still getting the problem in the OP. Using Mac OS High sierra, homebrew cask installed gui emacs 25.3.1, using ipython3 as my emacs python shell – xdavidliu Mar 15 '18 at 21:15
  • @xdavidliu macOS and ipython may both add their own complications, I suggest opening a separate question. – npostavs Mar 16 '18 at 01:29