简体   繁体   English

Vscode 自动完成功能不适用于 Jupyter Notebook

[英]Vscode autocompletion doesn't work for Jupyter Notebook

I recently started using Jupyter Notebooks on vscode but i've notices that code autocompletion doesn't work properly.我最近开始在 vscode 上使用 Jupyter Notebooks,但我注意到代码自动完成功能无法正常工作。

If i create a regular .py file everything works correctly as you can see.如果我创建一个常规的 .py 文件,一切正常,如您所见。 It shows function signature and docstring.它显示了函数签名和文档字符串。 In both core python language and extern modules.在核心 python 语言和 extern 模块中。

正确的自动完成核心

正确的自动完成外部

But if i try the same in a .ipynb file it completely ignores autocompletion for print()但是如果我在 .ipynb 文件中尝试相同的方法,它会完全忽略 print() 的自动完成

错误的自动完成

And what confuses me too if that for example it shows me np.sum() docstring but it doesn't show me any np.concatenate() information gamong any other np.functions or other modules如果例如它向我显示 np.sum() 文档字符串但它没有向我显示任何其他 np.functions 或其他模块中的任何 np.concatenate() 信息,那么我也感到困惑

[ [自动完成 np.sum4

自动完成 np.concatenate

Just in case im using Vscode and an conda enviroment as my python interpreter.以防万一我使用 Vscode 和 conda 环境作为我的 python 解释器。 Here is my settings.json file:这是我的 settings.json 文件:

{
"python.dataScience.jupyterServerURI": "local",
"python.pythonPath": "C:\\Users\\myUser\\anaconda3\\envs\\myEnv\\python.exe"
}

According to your description, the reason for this situation is that different language services provide different functions such as automatic completion and prompts.根据您的描述,出现这种情况的原因是不同语言服务提供的自动补全、提示等功能不同。

For the " print() " and " np.concatenate() " you mentioned, it is recommended that you use the " Pylance " extension, which provides excellent language services and auto-complete functions.对于你提到的“ print() ”和“ np.concatenate() ”,建议你使用“ Pylance ”扩展,它提供了优秀的语言服务和自动全功能。

Please add the following settings in settings.json :请在 settings.json 中添加以下settings.json

"python.languageServer": "Pylance",

在此处输入图片说明

在此处输入图片说明

Update:更新:

Starting from November 2020, the function of Jupyter notebook in VSCode is provided by the extension "Jupyter", which uses the "IntelliSense" provided by the extension "Jupyter".从 2020 年 11 月开始,VSCode 中 Jupyter notebook 的功能由扩展“Jupyter”提供,它使用扩展“Jupyter”提供的“IntelliSense”。 And in "VSCode-insider" Jupyter notebook has better "IntelliSense":而在“VSCode-insider”中,Jupyter notebook 有更好的“IntelliSense”:

在此处输入图片说明

Github link: Hover Documentation Pop up does not work after VSCode 1.52 update . Github 链接: Hover 文档弹出窗口在 VSCode 1.52 更新后不起作用

This has helped in my case, simply add to settings.json the following:这对我有帮助,只需在settings.json添加以下内容:

For Windows对于 Windows

"python.autoComplete.extraPaths": [
    "C:\\Users\\<user_name>\\AppData\\Local\\Programs\\Python\\Python38\\python.exe"
    ],

For Linux对于 Linux

"python.autoComplete.extraPaths": [
    "/usr/bin/python3"
    ],

For more information:想要查询更多的信息:

https://code.visualstudio.com/docs/python/editing https://code.visualstudio.com/docs/python/editing

For other tips, visit:有关其他提示,请访问:

https://code.visualstudio.com/docs/python/jupyter-support https://code.visualstudio.com/docs/python/jupyter-support

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM