Skip to content

Instantly share code, notes, and snippets.

@benjaminmgross
Last active October 10, 2019 04:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benjaminmgross/0fffd01f9037aaa76a9e to your computer and use it in GitHub Desktop.
Save benjaminmgross/0fffd01f9037aaa76a9e to your computer and use it in GitHub Desktop.
Linux Users: Extra Space in iPython Tab Completion when Using Conda (Fix) @cpcloud

Disclaimer: Although I'm a python developer, I'm not someone who has built libraries from source. Use this gist at your own peril.

##Intro

If you're running Linux, you may have installed anaconda to replace your package management needs, and loved it. Except when you fire up iPython you get an annoying "extra space" for your tab completion... that hasn't been patched yet.

When looking here and here, it appears to still be an issue.

With some hand-holding of @cpcloud (as in, "he held mine"), he was able to fix that problem for me today with very little effort.

###Step 1

Make sure you have libreadline-dev installed on you Linux box a la:

$ sudo apt-get install libreadline-dev 

###Step 2

Download and build Python 2.7.8 from source. Can also be found @cpcloud's gist:

$ wget https://www.python.org/ftp/python/2.7.8/Python-2.7.8.tar.xz
$ tar xvf Python-2.7.8.tar.xz

###Step 3

Compile & Make the Install

This portion comes for @kbg 's post about this very issue

$ cd Python-2.7.8
$ ./configure --enable-shared --enable-ipv6 --enable-unicode=ucs4 --prefix=/usr
$ make -j `nproc`

###Step 4

Copy the compiled libreadline.so object into your ../anaconda/lib/python2.7/lib-dynload/ folder.

 #Find where `readline.so` is located
$ find -name 'readline.so'

 #came back ./build/lib.linux-x86_64-2.7/readline.so
$ cp ./build/lib.linux-x86_64-2.7/readline.so ~/anaconda/lib/python2.7/lib-dynload/

###Step 5

Remove the conda readline install

$ conda remove readline

###Step 6

Check to make sure it worked

Close and re-open iPython, and try your tab completion (worked for me).

@jjhelmus
Copy link

FYI, the reason this works is that you are linking the Python readline module, readline.so against the system GNU readline library, libreadline.so.6. Although this fixes the extra space issue it makes the Anaconda Python install non-portable which may or may not be a concern.

@benjaminmgross
Copy link
Author

Thanks for the comment @jjhelmus. Just started using conda, so frankly losing the from iPython was my primary concern. As I don't do much (read: any) environment creation with conda, could you clarify? Are you saying that I won't be able to conda create -n <new_env> now that I've applied this libreadline hack to conda?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment