Python 如何在不使用选项卡的情况下在 jupyter notebook 中自动完成?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/45390326/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 16:58:22  来源:igfitidea点击:

How to get autocomplete in jupyter notebook without using tab?

pythonjupyter-notebook

提问by physicsnoob1000

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

%config IPCompleter.greedy=True

but this requires the tab button to be pressed

但这需要按下选项卡按钮

采纳答案by physicsGuy

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

jupyter有一个名为Hinterland的扩展,它在输入时自动显示下拉菜单。还有一些其他有用的扩展。

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.

为了安装扩展,您可以按照此github repo上的指南进行操作。要轻松激活扩展,您可能需要使用扩展配置器

回答by Wenmin Wu

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.

Jupyter Notebook 的自动完成非常弱,即使有腹地扩展也是如此。感谢基于深度学习的代码自动完成的想法。我开发了一个基于 TabNine 的 Jupyter Notebook 扩展,它提供基于深度学习的代码自动完成。这是我工作的 Github 链接:jupyter-tabnine

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

它现在可以在pypi 索引上使用。只需发出以下命令,然后享受它:)

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

demo

演示

回答by Sanchit Kumar

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

正如上面@physicsGuy 所提到的,您可以使用腹地扩展。简单的步骤来做到这一点。

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

使用 conda forge 通道安装 nbextension。只需在 conda 终端中运行以下命令:

conda install -c conda-forge jupyter_nbextensions_configurator

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

下一步启用腹地扩展。在 conda 终端中运行以下命令:

jupyter nbextension enable hinterland/hinterland

That's it, done.

就这样,大功告成。

回答by Micah Timileyin

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

%config IPCompleter.greedy=True在以这种方式导入 numpy 或 pandas 之类的包后,无需执行此操作; import numpy as npimport 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.

然后你输入pd.然后点击标签按钮,它会显示所有可能的方法,使用起来非常简单和直接。

回答by Hearaman

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

我正在使用 Jupiter Notebook 5.6.0。在这里,为了获得自动建议,我只是在输入至少一个字符后按 Tab 键。

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

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

要获取导入库中的方法和属性,请使用与 Alice 相同的 Tab 键

  import numpy as np

  np. --> Hit Tab key

回答by Pravin kumar

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

将以下内容添加到 jupyter 实验室的键盘用户首选项(设置-> 高级系统编辑器)

{
    "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"
        }

    ]
}