vscode-jupyter: Jupyter notebook kernel changes not detected to Pylance

Environment data

  • VS Code version: 1.57.1
  • Jupyter Extension version (available under the Extensions sidebar): v2021.6.999406279
  • Python Extension version (available under the Extensions sidebar): v2021.6.944021595
  • OS (Windows | Mac | Linux distro) and version: Windows 19043
  • Python and/or Anaconda version: 3.8.5
  • Type of virtual environment used (N/A | venv | virtualenv | conda | …): venv
  • Jupyter server running: Local

Expected behaviour

Upon changing the kernel in the top right Pylance should detect module changes and resolve imports

Code_AIlNLawSya

Actual behaviour

Pylance will only detect kernel changes if you change the interpreter via the command palette

Before changing via command palette Code_5gyZtvgN7r

After changing Code_A4F75UVgZw

Imports resolve

Steps to reproduce:

  1. Create a venv and install any pip module foo
  2. Create a notebook and import foo
  3. The pylance import detection will not update via changing kernel
  4. Changing via Python: Select Interpreter in the command palette will update Pylance

Note: code execution will work as if the venv is selected, but highlighting doesn’t. Another note: I’m sure a lot of my lingo I’m using is incorrect, I’m just starting out 😃

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 2
  • Comments: 24 (19 by maintainers)

Most upvoted comments

Hello, folks.

I’ve found a workaround for this issue. I’ve to configure python.analysis.extraPaths in settings.json of the current project in VSCode: { “python.analysis.extraPaths”: [ “path_to_venv_site_pakages” ], }

I’m working in a local project with a conda venv enviroment, so the config looks like: { “python.analysis.extraPaths”: [ “D:\Users\hs\Envs\udemyDSPy\lib\site-packages” ], } As the config is specific to project, we can change this in other projects to point the right venv packages import location.

*Note.: I’m using VSCode 1.64.2 version.

Woo hoo…