microsoft / pylance-release

Documentation and issues for Pylance
Creative Commons Attribution 4.0 International
1.67k stars 770 forks source link

"Import could not be resolved" after installing the package #6050

Open ibobak opened 6 days ago

ibobak commented 6 days ago

Type: Bug

The problem is that pylance continues to report error even after package installation.

The sequence of action was as on the picture. Steps to reproduce:

  1. install anaconda
  2. open attached notebook, run it under base environment. You will get an error in the last cell because the package is missing
  3. pip install gap-stat
  4. run the last cell. it works. but pylance is still reporting the problem (which does not exist any more)

The notebook is attached (rename to ipynb): kmeans.ipynb.txt

image

Extension version: 2024.6.1 VS Code version: Code 1.90.2 (5437499feb04f7a586f677b155b039bc2b3669eb, 2024-06-18T22:33:48.698Z) OS version: Linux x64 6.4.6-060406-generic Modes:

System Info |Item|Value| |---|---| |CPUs|Intel(R) Xeon(R) CPU E5-2696 v4 @ 2.20GHz (88 x 1197)| |GPU Status|2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: disabled_software
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: disabled_off| |Load (avg)|1, 2, 1| |Memory (System)|251.76GB (241.06GB free)| |Process Argv|--crash-reporter-id 27d42247-63fb-4d9e-9cb0-87d9974843dc| |Screen Reader|no| |VM|50%| |DESKTOP_SESSION|ubuntu-xorg| |XDG_CURRENT_DESKTOP|Unity| |XDG_SESSION_DESKTOP|ubuntu-xorg| |XDG_SESSION_TYPE|x11|
A/B Experiments ``` vsliv368:30146709 vspor879:30202332 vspor708:30202333 vspor363:30204092 vscoreces:30445986 vscod805:30301674 binariesv615:30325510 vsaa593:30376534 py29gd2263:31024239 c4g48928:30535728 azure-dev_surveyone:30548225 2i9eh265:30646982 962ge761:30959799 pythongtdpath:30769146 welcomedialog:30910333 pythonnoceb:30805159 asynctok:30898717 pythonregdiag2:30936856 pythonmypyd1:30879173 h48ei257:31000450 pythontbext0:30879054 accentitlementst:30995554 dsvsc016:30899300 dsvsc017:30899301 dsvsc018:30899302 cppperfnew:31000557 dsvsc020:30976470 pythonait:31006305 jchc7451:31067544 chatpanelt:31048053 dsvsc021:30996838 9c06g630:31013171 pythoncenvpt:31062603 a69g1124:31058053 dvdeprecation:31068756 dwnewjupyter:31046869 2f103344:31071589 legacy_priority:31077528 ```
heejaechang commented 4 days ago

will it go away if you close and re-open the notebook? or if you reload vsocde?

ibobak commented 4 days ago

yes, it goes away if I close and open the notebook.

But this is not an option and here is why: I have Spark context running in this notebook, and many initialized pandas dataframes, which are quite hard to calculate. And if I close the notebook and re-open it again, I will have to re-initialize the Spark app, recalculate of my dataframes, etc., which is a hard routine and takes a lot of time. Therefore, keeping a notebook running (even with false errors from pylance) is better than closing and re-opening of it.

But anyway, it would be good to have a command in Ctrl + Shift + P named "Pylance: restart scanning of files/notebooks" which would just do the job

ibobak commented 4 days ago

I don't know how the guys from PyCharm team did it, but they re-scan of all installed packages of the current environment just as soon as the new package arrives. It would be good to have this here too.

ibobak commented 4 days ago

I see that this bug in "needs repro" status. I don't know if you noticed this: I provided a notebook file in my original message, together with steps to reproduce.

rchiodo commented 3 days ago

This could be this issue here: https://github.com/microsoft/vscode/issues/199800

The root cause of the problem is you change your kernel and we (Pylance) never get told about it. So we think the current interpreter is a different one.

That's why Heejae asked if it went away if you closed and opened the notebook, we get the initial interpreter correctly then.