106

Tab completion on IPython seems not to be working. For example,

import numpy
numpy.<tab>

simply adds a tab.

import numpy
num<tab>

just adds a tab, too. Could you please suggest some possible causes for this problem? I am running Windows 7 and Python 2.6.5.

Trevor Boyd Smith
  • 18,164
  • 32
  • 127
  • 177
djpark121
  • 1,191
  • 3
  • 10
  • 5
  • 1
    Solution below worked for me - did it work for you? If so you should mark the answer accepted. – bacar Jul 02 '11 at 14:21
  • Nothing below worked for me. Have the latest pyreadline. Running jupyter notebook on python 3.5. – Michael Szczepaniak Sep 30 '16 at 01:12
  • In case it was working and then it stopped working after you pressed some random keys, then check if the type of cell was accidentally changed from "Code" to something else, like "Markdown" or "Raw NBConvert". – Sorin Postelnicu Oct 04 '17 at 19:05
  • if you just installed a new python module and ipython does not do import autocomplete, go [here](https://stackoverflow.com/questions/9151003/how-do-i-add-a-module-to-the-ipython-autocomplete) – Trevor Boyd Smith Aug 30 '18 at 14:29
  • `jedi` upgrade from 0.17 to 0.18 is buggy and disables IPython tab completion. See the answer from Dec 2020 below. – Abel Cheung Jan 04 '21 at 03:05
  • None of the solutions are getting me the whole way there. I tried installing `pyreadline` and downgrading `jedi` and `parso`. What's happening for me is I can see the hint, which looks correct, but when I hit tab, it doesn't just populate the hint, which is why I'd expect it to do. – szeitlin Apr 07 '22 at 17:35

19 Answers19

99

Be sure you have installed the pyreadline library. It is needed for tab completion and other IPython functions - in Windows it doesn't come with the IPython package and you have to install it separately -

> pip install pyreadline
Brian Burns
  • 20,575
  • 8
  • 83
  • 77
joaquin
  • 82,968
  • 29
  • 138
  • 152
  • 1
    @joaquin I tried to install this for mac using `install gnureadline`, but i'm still not able to get tab completion when I do something like `numpy.`. Do you know why this is? – TheRealFakeNews Sep 01 '15 at 18:14
  • @AlanH Sorry, no idea about MAC. Maybe you should open a new, specific question. – joaquin Sep 01 '15 at 19:32
  • 1
    FYI, if it's not working right away(which was the case for me), start the new console. – Alby Dec 28 '15 at 21:02
  • 2
    Adding a recommendation to use Anaconda or Miniconda to manage installs. I just installed ipython (`conda install ipython`) and had no tab completion issues. You can use it concurrently with pip. – Kenny Jan 07 '16 at 22:15
  • 4
    I think this answer is out of date, as iPython doesn't rely on pyreadlines since version 5.0, and pyreadlines has not been developed since 2017 -- See https://ipython.org/pyreadline.html – Olsgaard Sep 30 '20 at 08:42
78

In case anyone is using the recent 7.19.0 and autocomplete does not work, try downgrading jedi to 0.17.2:

pip install jedi==0.17.2

See https://github.com/ipython/ipython/issues/12740 for details.

ᄂ ᄀ
  • 5,669
  • 6
  • 43
  • 57
  • This reflects the status quo as of Jan 2021. `parso` package would need to be downgraded to 0.7.1 as well. – Abel Cheung Jan 04 '21 at 02:59
  • 1
    @Augusto It did seem to work for me at the beginning. But after the first code completion, it somehow breaks again. Meaning, for example after typing a loaded library name and DOT next to it, when I hit Tab, nothing happens, when it should list the options for modules in that library in a dropdown... – caydin Jan 18 '21 at 21:35
  • I'm using Python 3.6.8/ipython 7.16.1 and it worked for me. – felixc Mar 19 '21 at 00:00
  • This fixed it for me two with Python 3.7.7/ipython 7.22. Thanks. – packoman Apr 12 '21 at 10:13
  • This change (particularly the downgrade of `parso`) fixed for me the work of both `ptpython` and `ipython` `pip install parso==0.7.1` – Mna Jul 16 '21 at 15:17
18
pip uninstall jedi --yes

and

pip install pyreadline

The current Ipython with the Jupyter notebook doesn't require jedi.. So you have to just uninstall it with the above command.

I got it from here.

Sezgin İbiş
  • 228
  • 2
  • 6
  • 1
    This solution worked for me. Python `3.8.10`, IPython `7.22.0`, macOS. Thank you! – fepegar Jul 13 '21 at 13:29
  • 1
    This solution worked for me in 2021. Not sure what the impact will be for not having jedi, or how it got on my system in the first place for that matter. – user391339 Aug 13 '21 at 20:34
  • I can confirm this worked for me. Python `3.8.12`, IPython `7.21.0`, Ubuntu. – gdm Oct 14 '21 at 11:00
6

pip told me I had pyreadline version 1.7.1 installed

C:\Users\me>pip freeze | grep readline
pyreadline==1.7.1

Upgrading pyreadline fixed it for me:

C:\Users\me>pip install --upgrade pyreadline

C:\Users\me>pip freeze | grep readline
pyreadline==2.0
Rabarberski
  • 23,854
  • 21
  • 74
  • 96
4

Your ipythonrc file may be out of date. Try running

ipython -upgrade
zwalker
  • 346
  • 5
  • 9
3

Downgrading iPython did the trick.

pip install --upgrade ipython==5.8.0
Justin Case
  • 189
  • 1
  • 1
  • 8
3

I had this problem. I solved by downgrade the python-parso package

downgrading the python-parso package (0.8.0-1 => 0.6.2-1)

2

The classic 'have you tried turning it off and on again' worked for me.

pip uninstall ipython
pip install ipython
Shashank Agarwal
  • 2,769
  • 1
  • 22
  • 24
2

This should definitely work as it worked in my case

conda install ipython  
pip install jedi==0.17.2
Prajot Kuvalekar
  • 5,128
  • 3
  • 21
  • 32
1

As of right now, on a OSX, pip installed ipython doesn't give tab completion, pyreadline release.py is busted .. what WFM:

easy_install ipython readline

YMMV.

Skylar Saveland
  • 11,116
  • 9
  • 75
  • 91
1

Someone else in StackOverflow posted this link: http://www.vankouteren.eu/blog/2009/06/getting-ipython-readline-and-auto-completion-to-work-on-mac-os-x/

Its basicly easy_install readline than discover where the readline egg got installed and edit the ipython bin script to use this readline:

  1. Install the "official" readline: easy_install readline
  2. Discover where it is. Look at /Library/Python/site-packages/readline-*.egg or in your Virtualenv counterpart
  3. Discover where ipython bin is: which ipython
  4. Add ONE LINE to this file, adding the readline egg path right after import sys line.

My virtualenved ipython bin script got working as follow:

#!/Users/alanjds/src/git/cervejeiras/venv/cervejeiras-lfs/bin/python
# EASY-INSTALL-ENTRY-SCRIPT: 'ipython==0.13.1','console_scripts','ipython'
__requires__ = 'ipython==0.13.1'
import sys

### ONLY LINE ADDED:
sys.path.insert(0, '/Users/alanjds/src/git/cervejeiras/venv/cervejeiras-lfs/lib/python2.6/site-packages/readline-6.2.4.1-py2.6-macosx-10.6-fat.egg')
####

from pkg_resources import load_entry_point

if __name__ == '__main__':
    sys.exit(
        load_entry_point('ipython==0.13.1', 'console_scripts', 'ipython')()
    )
alanjds
  • 3,972
  • 2
  • 35
  • 43
1

I realize this is a really old question, but none of the answers above worked for me (And this is the first hit you get when you google a question of this nature).

I should mention that this is NOT exclusive to windows, I had the problem running CentOS 6.5 and Python 2.7

Here is what I did:

apt-get/yum install ncurses-devel
#If you want history in iPython:
apt-get/yum install sqlite-devel
easy_install ipython readline
ipython

In [1]: from 
Display all 391 possibilities? (y or n)

If you don't have the -devel packages, your install will fail when it comes time to link them and build the eggs.. Hope this helps others!

steve-gregory
  • 7,396
  • 8
  • 39
  • 47
1

I had this problem and knew that I had the pip installed for the module I was looking for. Performing $ ipython --init solved the problem for me.

mvnicosia
  • 31
  • 4
0

I had to mv ~/.ipython{,.bak} in my case.

maximk
  • 188
  • 1
  • 4
0

If you use Jupyter notebook and you still did get Tab auto-complete working after you tried all the steps suggested in the post here, you might want to check if you are trying to use the Tab auto-completion within a function definition. Ifyour import statements are part of the function such as below, you will not get the Tab auto-completion. You need to put the import statements outside the function and also execute them once before asking for auto-completion on the packages.

def myfunction():
    import pandas as pd
    import numpy as np

    a = pd.DataFrame(np.random.normal(1,3, (4,4))
    return a
ds2000
  • 21
  • 1
  • 4
0

I faced the same problem with the numpy library. The issue is with the particular version of ipython or jupyter notebook and it is resolved by simply updating ipython or jupyter. If you are using a conda environment like anaconda or miniconda then update ipython in that environment by using

conda update ipython

In case of anaconda you also need to update the qtconsole

conda update qtconsole

Sometimes anaconda constraints the update of ipython then try

conda update -all

If you are not using a environment then directly update using pip

pip update ipython
0

I solved my issue by installing jedi-language-server:

pip install -U jedi-language-server

PS, I was installed Ipython from Conda in a virtual env and used the above command when the env was activated.

Ashkan Mirzaee
  • 300
  • 4
  • 14
0

To check if ipython and the modules it uses match, run pip check ipython.
For my configuration with ipython 7.25 in July 2021, this gave a good clear warning:

ipykernel 6.0.1 has requirement importlib-metadata<4; python_version < "3.8.0", but you have importlib-metadata 4.6.0.

You may of course see different warnings -- this is just an example, unrelated to tab completion.

Then to downgrade it, e.g. pip install 'importlib-metadata<4' # don't forget the 'quotes'

Successfully uninstalled importlib-metadata-4.6.0
Successfully installed importlib-metadata-3.10.1


Also useful:
  • pip list -- everything in your $PYTHONPATH, with version and location
  • pip check -- everything
  • pip show ipython --

Requires: traitlets, pygments, jedi, decorator, pickleshare, pexpect, appnope, matplotlib-inline, setuptools, prompt-toolkit, backcall

but to see the required versions you have to look at .../site-packages/ipython-*.dist-info/METADATA

denis
  • 21,378
  • 10
  • 65
  • 88
-1

Pyreadline is needed by ipython. Install pyreadline. This was done in Windows 7. Get pyreadline zip, pyreadline-master.zip, unzip. In powershell change directory into uzipped pyreadline, make sure python is set in Path, and enter commandpython setup.py install This will intall pyreadline in C:\Python27\Lib\site-packages