Previous INDEX Next
Writing emacs commands Windows Subsystem for Linux

OS X El Capitan, emacs and python

I recently wanted to write some Python code on my Macbook, but when starting the Python interpreter under emacs (25.2), I found the following warning generated:

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

Google led me to this bug report, with the following explanation/workaround for the issue:

This happens when python uses a libedit-based readline module, which is the default on macOS. This can be worked around by installing a GNU readline based module instead, for example, using setuptools:

  sudo easy_install gnureadline

And then rename the system's readline so that it won't be loaded:

  cd /System/Library/Frameworks/Python.framework/Versions/2.7/
      lib/python2.7/lib-dynload
  mv readline.so readline.so.bak

The above rename won't work on later versions of MacOS, due to System Integrity Protection. This can be disabled by rebooting with cmd-R pressed, going to Utilities->Terminal and typing:

  csrutil disable
  reboot

However, I'm not sure that the rename is required, as the install of gnureadline seems to ensure that the GNU version of the library is found first. Here's sys.path from the Mac, after the gnureadline install:

  [mark@aqua:/]$ python
  Python 2.7.10 (default, Oct 23 2015, 19:19:21) 
  [GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
  Type "help", "copyright", "credits" or "license" for more information.
  >>> import sys
  >>> print sys.path
  ['',
  '/Library/Python/2.7/site-packages/gnureadline-6.3.8-py2.7-macosx-10.11-intel.egg',
  '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip',
  '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
  '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
  '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
  '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/
    lib-scriptpackages',
  '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python',
  '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
  '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old',
  '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload',
  '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC',
  '/Library/Python/2.7/site-packages']
  >>>
Previous INDEX Next
Writing emacs commands Windows Subsystem for Linux