Home > Software design >  Pylance does not show docstring for local import in VSCode Jupyter notebook
Pylance does not show docstring for local import in VSCode Jupyter notebook

Time:09-10

I am working on a Jupyter notebook on VSCod. when I import functions that I have in another local folder, VSCode does not show the docstring of the function. When I hover on the file name in the notebook, I see the message Import "scripts" could not be resolved - Pylance.

It works correctly with libraries like Numpy and Pandas and if I defined the function on the same notebook. It also works perfectly with python .py files.

Code to reproduce where the file scripts is in some/path:

import sys
sys.path.append("some/path")
from scripts import func1

This is my settings.json file

{
    "gitlens.defaultDateFormat": null,
    "editor.inlineSuggest.enabled": true,
    "python.defaultInterpreterPath": "~/opt/anaconda3/envs/test/bin/python",
    "python.languageServer": "Pylance",
    "python.analysis.autoSearchPaths": true,
    "python.analysis.extraPaths": [
        "./tools"
    ],
    "editor.minimap.enabled": false,
    "github.copilot.enable": {
        "*": true,
        "yaml": true,
        "plaintext": false,
        "markdown": false
    }
}

CodePudding user response:

After hours of searching, here is the solution per this comment. Just disable the Pylance LSP Notebooks experiment by adding the following to the settings.json file for user:

"python.pylanceLspNotebooksEnabled": false

and this in the workspace settings.json file just to include your local module.

"python.languageServer": "Pylance",
"python.analysis.extraPaths": [
    "path/to/local/module"
]

CodePudding user response:

I have the same trouble but the solution proposed does not work completely for me... It shows only

`(function) siges_seine: ((mailleId: int) -> DataFrame) | Any``

but not the docstring I have written.

  • Related