microsoft / vscode-python

Python extension for Visual Studio Code
https://aka.ms/pvsc-marketplace
MIT License
4.28k stars 1.17k forks source link

Python Packages/Libraries Not Recognized #20964

Closed Matt-Greer closed 1 year ago

Matt-Greer commented 1 year ago

Type: Bug

• Start a new python file, or open a saved one • For me, simply adding numpy or xlwings demonstrates the issue • Unrecognized libraries are white (based on my theme) indicating an issue with vscode recognizing them, or something. When I hover over a recognized library, vscode will get a little flyover pop-up "(module) pandas", for example. But with xlwings and numpy (and who knows what other modules?) they're white, not orange, and I can't ctrl-click on them to bring up the module code.

This is only an issue with a file in vscode, and not a jupyter file. Jupyter still recognizes the livraries.

VS Code version: Code 1.77.0 (7f329fe6c66b0f86ae1574c2911b681ad5a45d63, 2023-03-29T10:02:16.981Z) OS version: Windows_NT x64 10.0.19045 Modes: Sandboxed: No

System Info |Item|Value| |---|---| |CPUs|12th Gen Intel(R) Core(TM) i9-12900K (24 x 3187)| |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_renderer: enabled_on
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: disabled_off| |Load (avg)|undefined| |Memory (System)|31.71GB (19.76GB free)| |Process Argv|--crash-reporter-id aefb1632-fee3-4643-b69b-93a21180d212| |Screen Reader|no| |VM|0%|
Extensions (9) Extension|Author (truncated)|Version ---|---|--- xml|Dot|2.5.1 isort|ms-|2022.8.0 python|ms-|2023.6.0 vscode-pylance|ms-|2023.3.40 jupyter|ms-|2023.3.1000892223 jupyter-keymap|ms-|1.1.0 jupyter-renderers|ms-|1.0.15 vscode-jupyter-cell-tags|ms-|0.1.8 vscode-jupyter-slideshow|ms-|0.1.5 (1 theme extensions excluded)
A/B Experiments ``` vsliv368:30146709 vsreu685:30147344 python383:30185418 vspor879:30202332 vspor708:30202333 vspor363:30204092 vslsvsres303:30308271 vserr242cf:30382550 pythontb:30283811 vsjup518:30340749 pythonptprofiler:30281270 vsdfh931:30280409 vshan820:30294714 vstes263:30335439 vscoreces:30445986 pythondataviewer:30285071 vscod805cf:30301675 binariesv615:30325510 bridge0708:30335490 bridge0723:30353136 cmake_vspar411:30581797 vsaa593:30376534 pythonvs932:30410667 cppdebug:30492333 vsclangdc:30486549 c4g48928:30535728 dsvsc012cf:30540253 pynewext54:30695312 azure-dev_surveyone:30548225 vscccc:30610679 nodejswelcome1cf:30587006 282f8724:30602487 pyind779:30671433 89544117:30613380 pythonsymbol12:30671437 6233i204:30672705 pythonb192cf:30669361 azdwalk:30687957 pythonms35:30701012 ```

Screenshot 2023-03-30 173513

Matt-Greer commented 1 year ago

I suppose I should mention, the code will run just fine...

zero00072 commented 1 year ago

Is this document help you? Some times I forgot to switch environment. And it refers to system-wide Python.

Matt-Greer commented 1 year ago

Is this document help you? Some times I forgot to switch environment. And it refers to system-wide Python.

* [Select and activate an environment](https://code.visualstudio.com/docs/python/environments#_select-and-activate-an-environment)

I have three environments. It happens regardless of the environment that is activated. I deleted all the custom themes and disabled all extensions save python, and it was still happening. This happens on multiple computers.

Thank you for the suggestion but, sadly, that is not the issue.

Matt-Greer commented 1 year ago

I uninstalled VScode and installed version 1.74.3. The issue has gone away. However, when I reinstalled, I had to remove and reinstall the Python extension (ID: ms-python.python) as it was not compatible with this earlier vscode version. So I can't say whether or not the issue is with vscode, or python? So I have MS Python IntelliSense v2022.20.2 installed currently.

Actually, it might be pylance? On another computer I had version v2023.3.40 and I was told it needed an update, so I updated it and the issue, which wasn't present on that computer, is now present. But... the version hasn't changed? Still says it's version v2023.3.40.

idk what to do here other than remove all installs of vscode and revert aback to version 1.74.3 for the time being. I'll try installing newer and newer versions and see what happens. Any advice y'all have would be very much appreciated.

Matt-Greer commented 1 year ago

OK, the issue is pylance. I don't know why I wasn't able to alleviate the issue before by disabling it, but... I think perhaps I didn't disable it thinking it was 100% required. I installed vscode 1.77, installed the ms python extension which installed several other extensions including pylance 2023.3.40. I uninstalled pylance and the issue went away. I was able to hit ctrl and hover over the 'import ' and both pandas, xlwings, and numpy were recognized and I could click on 'em to bring up their code.

So at this point, I don't know how to force vscode to load an older version of pylance and/or the ms python extension. My impression is they go together? What should I do next?

Matt-Greer commented 1 year ago

OK, I figured out how to install an earlier version of pylance. Sorry for the trouble folks.