162

I would like to get an autocompletion feature in notebooks i.e. when I type something, a dropdown menu appears, with all the possible things I might type, without having to press the tab button. Is there such a thing?

I tried :

%config IPCompleter.greedy=True

but this requires the tab button to be pressed

Paradox
  • 738
  • 12
  • 30
physicsnoob1000
  • 1,723
  • 2
  • 11
  • 8

7 Answers7

130

There is an extension called Hinterland for jupyter, which automatically displays the drop down menu when typing. There are also some other useful extensions.

In order to install extensions, you can follow the guide on this github repo. To easily activate extensions, you may want to use the extensions configurator.

Brian Burns
  • 20,575
  • 8
  • 83
  • 77
physicsGuy
  • 3,437
  • 3
  • 27
  • 35
  • 3
    If i am using a remote machine running jupyter notebook and I use it from my local machine via browser, where should I install the extensions? – thebeancounter Sep 03 '18 at 11:53
  • 2
    @thebeancounter I have the extension installed only locally, that is on the machine where I access the notebook via browser. I don't have any extensions installed on my remote machine that runs jupyter notebook. – physicsGuy Sep 03 '18 at 12:13
  • 6
    I've installed hinterland and it will only auto complete basic python stuff but will not autocomplete module functions (eg pd, np etc) how can I make it autocomplete those as well like pycharm? – thebeancounter Sep 12 '18 at 14:09
  • @thebeancounter For me hinterland works with modules like numpy and pandas. Even if I do a relative import `import numpy as np` and type `np`, suggestions show up (e.g. np.abs). To troubleshoot this problem, more details on your setup are required. I'd suggest to open a separate question for your problem. – physicsGuy Sep 12 '18 at 14:30
  • 2
    For those who are not familiar with Jupyter Notebook like me, 1) follow the official instruction to install these things: https://jupyter-contrib-nbextensions.readthedocs.io/en/latest/install.html 2) install browser configurator UI, following: https://github.com/Jupyter-contrib/jupyter_nbextensions_configurator 3) Open the jupyter notebook using command in terminal: `jupyter notebook` – Jason May 07 '19 at 19:28
65

The auto-completion with Jupyter Notebook is so weak, even with hinterland extension. Thanks for the idea of deep-learning-based code auto-completion. I developed a Jupyter Notebook Extension based on TabNine which provides code auto-completion based on Deep Learning. Here's the Github link of my work: jupyter-tabnine.

It's available on pypi index now. Simply issue following commands, then enjoy it:)

pip3 install jupyter-tabnine
jupyter nbextension install --py jupyter_tabnine
jupyter nbextension enable --py jupyter_tabnine
jupyter serverextension enable --py jupyter_tabnine

demo

Wenmin Wu
  • 1,808
  • 12
  • 24
  • Works great! But it has killed my new line (Shift+Enter) doesn't work any more in Jupyter Notebook. Any workaround for that? – Hrvoje Oct 22 '19 at 08:25
  • 1
    @Harvey Hi, I block the first `Enter` to avoiding misoperation. If the hint window is shown, the first `Enter` will trigger the closing of the window. For now, if you want new line when the hint is shown, you can just issue `Enter` and then issue `Enter` (or `Shift` + `Enter` if you want to execute current cell and create a new one.) I'm not sure whether it's a good design. Do let me know your fellings and suggestions. – Wenmin Wu Oct 25 '19 at 06:55
  • On my laptop keyboard ´fn´ + ´Enter´ works. I'm getting used on than. Expected behavior was Alt+Enter for new line in cell and Shift+Enter for execution. Anyway considering how useful this plugin is this is just minor thing. Thank you! – Hrvoje Oct 25 '19 at 08:15
  • 2
    In case one may have the `Permission denied` error when trying to install for jupyter, just add `--user` with the jupyter install command. – fytao Jan 29 '20 at 18:55
  • 4
    Also a kind warning: TabNine can take up a greate amount of memory and CPU resources. In my case, I run jupyter notebook from WSL(Ubuntu 18.04), and TabNine takes up ~1.5GB memory. The memory used can drop to ~200MB if you end the task from task manager and TabNine will autoboot itself the next time you type in your jupyter notebook. More details at https://github.com/zxqfl/TabNine/issues/43. – fytao Jan 29 '20 at 20:32
  • I tried it, but the drop down doesn't show stuff as good as hinterland, so I went back. – SledgeHammer Dec 08 '21 at 05:14
  • this code also work in android when i use jupyter? – Stink Dec 19 '22 at 08:34
29

I would suggest hinterland extension.

In other answers I couldn't find the method for how to install it from pip, so this is how you install it.

First, install jupyter contrib nbextensions by running

pip install jupyter_contrib_nbextensions

Next install js and css file for jupyter by running

jupyter contrib nbextension install --user

and at the end run,

jupyter nbextension enable hinterland/hinterland

The output of last command will be

Enabling notebook extension hinterland/hinterland...
      - Validating: OK
Khushal sharma
  • 423
  • 5
  • 10
18

As mentioned by @physicsGuy above, You can use the hinterland extension. Simple steps to do it.

Installing nbextension using conda forge channel. Simply run the below command in conda terminal:

conda install -c conda-forge jupyter_nbextensions_configurator

Next Step enabling the hinterland extension. Run the below command in conda terminal:

jupyter nbextension enable hinterland/hinterland

That's it, done.

Sanchit Kumar
  • 1,545
  • 1
  • 11
  • 19
  • 10
    `Enabling notebook extension hinterland/hinterland... - Validating: problems found: - require? X hinterland/hinterland` This is the error in doing this – Darshu Bc May 04 '19 at 08:43
  • 1
    run this two commands `jupyter contrib nbextension install --system` and `jupyter contrib nbextension install --user` and then this to see the list `jupyter nbextension list` – PiotrK Jun 27 '19 at 06:50
8

I am using Jupiter Notebook 5.6.0. Here, to get autosuggestion I am just hitting Tab key after entering at least one character.

 **Example:** Enter character `p` and hit Tab.

To get the methods and properties inside the imported library use same Tab key with Alice

  import numpy as np

  np. --> Hit Tab key
Hearaman
  • 8,466
  • 13
  • 41
  • 58
7

Without doing this %config IPCompleter.greedy=True after you import a package like numpy or pandas in this way; import numpy as np import pandas as pd.

Then you type in pd. then tap the tab button it brings out all the possible methods to use very easy and straight forward.

Ala Tarighati
  • 3,507
  • 5
  • 17
  • 34
1

Add the below to your keyboard user preferences on jupyter lab (Settings->Advanced system editor)

{
    "shortcuts":[
        {
            "command": "completer:invoke-file",
            "keys": [
                "Ctrl Space"
            ],
            "selector": ".jp-FileEditor .jp-mod-completer-enabled"
        },
        {
            "command": "completer:invoke-file",
            "keys": [
                "Ctrl Space"
            ],
            "selector": ".jp-FileEditor .jp-mod-completer-enabled"
        },
        {
            "command": "completer:invoke-notebook",
            "keys": [
                "Ctrl Space"
            ],
            "selector": ".jp-Notebook.jp-mod-editMode .jp-mod-completer-enabled"
        }

    ]
}
Pravinkumar
  • 129
  • 2
  • 10
  • 1
    Note: this question is about jupyter notebook. For JupyterLab there is [another question](https://stackoverflow.com/q/58445239/6646912) created prior to your answer and you answer might fit there better. Although I must say this is not the answer I would expect, it is technically correct - no using tab here ;) – krassowski Feb 02 '21 at 01:08