177

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

8 Answers 8

138

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.

Sign up to request clarification or add additional context in comments.

5 Comments

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 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.
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 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.
For those who are not familiar with Jupyter Notebook like me, 1) follow the official instruction to install these things: jupyter-contrib-nbextensions.readthedocs.io/en/latest/… 2) install browser configurator UI, following: github.com/Jupyter-contrib/jupyter_nbextensions_configurator 3) Open the jupyter notebook using command in terminal: jupyter notebook
69

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

7 Comments

Works great! But it has killed my new line (Shift+Enter) doesn't work any more in Jupyter Notebook. Any workaround for that?
@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.
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!
In case one may have the Permission denied error when trying to install for jupyter, just add --user with the jupyter install command.
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 github.com/zxqfl/TabNine/issues/43.
|
36

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

Comments

19

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.

2 Comments

Enabling notebook extension hinterland/hinterland... - Validating: problems found: - require? X hinterland/hinterland This is the error in doing this
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
14

If you are using Jupyter Lab, you can simply go to Settings > Code completion > Enable autocompletion. It will have the same effect as hinterland without installing any extension.

2 Comments

this is a great help, and should be correct answer
This is the best answer, works for me. But should be more specific it is under settings -> Settings Editor -> code completion -> Enable autocompletion
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

1 Comment

he want a solution without using tab key
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.

1 Comment

he want a solution without using tab key
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"
        }

    ]
}

1 Comment

Note: this question is about jupyter notebook. For JupyterLab there is another question 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 ;)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.