简体   繁体   中英

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.

If i create a regular .py file everything works correctly as you can see. It shows function signature and docstring. In both core python language and extern modules.

正确的自动完成核心

正确的自动完成外部

But if i try the same in a .ipynb file it completely ignores autocompletion for 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.sum4

自动完成 np.concatenate

Just in case im using Vscode and an conda enviroment as my python interpreter. Here is my settings.json file:

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

Please add the following settings in 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". And in "VSCode-insider" Jupyter notebook has better "IntelliSense":

在此处输入图片说明

Github link: Hover Documentation Pop up does not work after VSCode 1.52 update .

This has helped in my case, simply add to settings.json the following:

For Windows

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

For Linux

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

For more information:

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

For other tips, visit:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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