iPython 代码完成/点上的智能感知可能吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33700112/
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 13:48:35  来源:igfitidea点击:

iPython Code Completion / Intellisense on Dot Possible?

pythonipython

提问by Jarad

As someone trying to learn the ins and outs of Python (with emphasis on scientific computing - ie: pandas, numpy, scikit-learn), most of the gurus out there seem to recommend and use iPython notebooks. My biggest sticking point as a beginner/intermediate coder is that I NEED code completion / intellisense -like functionality from an IDE to learn the function parameters. I'm not hard-wired yet to just know what parameters are available at my current development.

当有人试图学习 Python 的来龙去脉(重点是科学计算——即:pandas、numpy、scikit-learn)时,那里的大多数大师似乎都推荐并使用 iPython 笔记本。作为初学者/中级编码员,我最大的症结在于我需要来自 IDE 的代码完成/类似智能感知的功能来学习函数参数。我还不是硬连线,只是知道我当前的开发中有哪些可用的参数。

In iPython, I noticed I can press Tabto show the drop-down of options (seen below as pd.) but I don't want to have to hit each time. That's not user-friendly for my needs. Instead, I would like it to show only available classes and methods when I press dot.

在 iPython 中,我注意到我可以按下Tab以显示选项的下拉列表(如下所示为 pd。)但我不想每次都点击。这对我的需求来说不是用户友好的。相反,我希望它在按 dot 时仅显示可用的类和方法。

Secondly, I notice that if I did say pd.read_csv(<TAB>, I get a lot more options than are the actual parameters in read_csv.

其次,我注意到如果我确实说了pd.read_csv(<TAB>,我得到的选项比read_csv.

Question: Can iPython automatically show accurate code completion options instantly after pressing dot / period? Also, is there a way to configure it to only show the available function parameters when within a function?

问题:按点/句点后,iPython 能否立即自动显示准确的代码完成选项?另外,有没有办法将其配置为仅在函数内显示可用的函数参数?

To make this question super-specific, I'm not asking about using any other IDE; I'm asking very specifically in regards to just iPython and wondering if there's a way to set some kind of configuration to achieve accurate "dot" display options instantly when pressing "dot" (no time delay).

为了使这个问题超级具体,我不是在问使用任何其他 IDE;我非常特别地询问 iPython 并想知道是否有办法设置某种配置以在按下“点”(无时间延迟)时立即实现准确的“点”显示选项。

enter image description here

在此处输入图片说明

Example below shows Desktopwhich is obviously not a parameter of pd.read_csv().

下面的示例显示Desktop这显然不是 的参数pd.read_csv()

enter image description here

在此处输入图片说明

回答by jme

You can press <Shift>-<Tab>to get a tooltip showing the function's signature:

您可以按<Shift>-<Tab>获取显示函数签名的工具提示:

enter image description here

在此处输入图片说明

Alternatively, invoking zip?opens a documentation pane at the bottom of the window.

或者,调用会zip?在窗口底部打开一个文档窗格。

As far as having the tooltip open automatically, I'm unsure. I'd guess that it isn't possible via configuration.

至于让工具提示自动打开,我不确定。我猜想通过配置是不可能的。

回答by DIGVIJAY SINGH

If you are using Jupyter notebook and your Intellisense is not working then type below and give a press TAB after (.)

如果您使用的是 Jupyter 笔记本并且您的 Intellisense 无法正常工作,请在下面输入并在 (.)

%config IPCompleter.greedy=True

%config IPCompleter.greedy=True

it will work for you as well.

它也适合你。

回答by Jarad

Almost 3 years later, I've finally come across a potential solution.

将近 3 年后,我终于找到了一个潜在的解决方案。

Answer: Install nbextensionsand enable the Hinterland extension.

:安装nbextensions并启用 Hinterland 扩展。

Enable code autocompletion menu for every keypress in a code cell, instead of only calling it with tab.

为代码单元格中的每个按键启用代码自动完成菜单,而不是仅使用选项卡调用它。

Here's what you do:

这是你要做的:

  1. pip install jupyter_contrib_nbextensions
  2. jupyter contrib nbextension install --user
  3. Start jupyter notebook(browser launches)
  4. One of the tabsshould now show "Nbextensions"
  5. There, you will find "Hinterland". Check the box to enable.
  1. pip install jupyter_contrib_nbextensions
  2. jupyter contrib nbextension install --user
  3. 开始jupyter notebook(浏览器启动)
  4. 其中的选项卡现在应该显示“ Nbextensions
  5. 在那里,您会找到“腹地”。选中该框以启用。

Hinterland has some adjustable options like:

腹地有一些可调整的选项,例如:

  • hinterland.hint_delay: delay in milliseconds between keypress & hint request.
  • hinterland.enable_at_start: Whether to enable hinterland's continuous hinting when notebook is first opened, or if false, only when selected from the help-menu item.
  • hinterland.hint_inside_comments: Whether to request hints while typing code comments. Defaults to false.
  • Other regex options: hinterland.exclude_regexp, hinterland.include_regexp, hinterland.tooltip_regexp
  • hinterland.hint_delay:按键和提示请求之间的延迟(以毫秒为单位)。
  • hinterland.enable_at_start: 是否在第一次打开 notebook 时启用腹地的连续提示,如果为 false,则仅当从帮助菜单项中选择时。
  • hinterland.hint_inside_comments:是否在键入代码注释时请求提示。默认为假。
  • 其他正则表达式选项:hinterland.exclude_regexp、hinterland.include_regexp、hinterland.tooltip_regexp


enter image description here

在此处输入图片说明

回答by Wenmin Wu

Now there's a better way to get accurate code completion operation. It can be triggered by any character you typed. Inspired by TabNine, I developed a code auto-completion extension for Jupyter Notebook Jupyter TabNine.

现在有一个更好的方法来获得准确的代码完成操作。它可以由您键入的任何字符触发。受 TabNine 的启发,我为 Jupyter Notebook 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 Vityata

This is what worked for me:

这对我有用:

pip install jupyter_contrib_nbextensions
jupyter contrib nbextension install --user
jupyter notebook

To see the Nbextensions tab if something has hidden it:

如果有东西隐藏了它,要查看 Nbextensions 选项卡:

jupyter nbextensions_configurator enable --user
  • under Nbextensions uncheck "disable confirguration for nbextensions without explicit compatibility ..." (disclaimer - all risks are yours for doing this)
  • select only
    • "Hinterland" for the formatting ones. I had some other nbextensions selected and somehow it was not working.
    • "Nbextension edit menu item" & "Nbestenision dashboard tab" (in order to see this tab again next time)
  • 在 Nbextensions 下取消选中“在没有明确兼容性的情况下禁用 nbextensions 的配置......”(免责声明 - 这样做的所有风险都是你的)
  • 选择
    • “腹地”用于格式化。我选择了其他一些 nbextensions,但不知何故它不起作用。
    • “Nbextension 编辑菜单项”和“Nbestenision 仪表板选项卡”(为了下次再次看到此选项卡)

enter image description here

在此处输入图片说明

回答by krassowski

If you are using JupyterLab, the jupyterlab-lsp extension(with pyls server installed) does invoke the completer automatically upon typing the dot ('.'):

如果您使用的是 JupyterLab,则jupyterlab-lsp 扩展(安装了 pyls 服务器)会在输入点 ('.') 时自动调用完成程序:

enter image description here

在此处输入图片说明

Pros:

优点:

  • (intelligent) completion suggestions are available even before the code gets executed (static analysis).
  • many other IDE-like features included (signature hints, diagnostics, rename, jump-to-definition, etc)
  • (智能)完成建议甚至在代码执行之前就可用(静态分析)。
  • 包括许多其他类似 IDE 的功能(签名提示、诊断、重命名、跳转到定义等)

Cons:

缺点:

  • requires the installation of three packages: the server & client extensions, and the language server
  • not yet as configurable as Hinterland (but it will be, WIP)
  • 需要安装三个包:服务器和客户端扩展,以及语言服务器
  • 还没有像 Hinterland 那样可配置(但它会是,WIP)

Assuming that you have node 8+, Python 3.5+ and JupyterLab 1.2+ already installed, you can install the current version with:

假设您已经安装了 node 8+、Python 3.5+ 和 JupyterLab 1.2+,您可以使用以下命令安装当前版本:

pip install --pre jupyter-lsp    # server extension
jupyter labextension install @krassowski/jupyterlab-lsp    # client extension
pip install python-language-server[all]     # language server

For more detailed and up-to-date installation instructions please see this link.

有关更详细和最新的安装说明,请参阅此链接

Disclaimer: I am one of the authors of this extension.

免责声明:我是此扩展程序的作者之一。