Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

correct autocompletion core

correct autocompletion extern

But if i try the same in a .ipynb file it completely ignores autocompletion for print()

incorrect autocompletion

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

[autocomplete np.sum4

autocomplete 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"
}
like image 835
aarribas12 Avatar asked Nov 04 '20 12:11

aarribas12


2 Answers

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",

enter image description here

enter image description here

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":

enter image description here

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

like image 193
Jill Cheng Avatar answered Oct 12 '22 20:10

Jill Cheng


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

like image 1
nferreira78 Avatar answered Oct 12 '22 20:10

nferreira78