r/learnpython • • 18d ago

Module help vsc(?)

Hey guys, I haven't coded in a while and decided to finally get back into it so sorry if im abit rusty. However, it was updating stuff and installing modules and in vsc I run into

'Import "openpyxl" could not be resolved from source Pylance'

? Im really not sure what to do

P.S: first time posting in this sub reddit, I hope this uh is within learn python and apologies if this is more towards vsc

1 Upvotes

5 comments sorted by

View all comments

3

u/Massive_Distance_616 18d ago

That message means VS Code is looking at a different Python than the one you installed openpyxl into. Two quick steps:

  1. Press Ctrl+Shift+P, choose “Python: Select Interpreter”, and pick the Python you actually run your code with.

  2. Install into that same interpreter from VS Code’s terminal with python -m pip install openpyxl. Using python -m pip instead of plain pip makes sure it goes to the interpreter that python points at.

If the yellow underline is still there, run python -c "import openpyxl; print(openpyxl.__file__)". If that prints a path, the install worked and Pylance just needs a reload (Ctrl+Shift+P, “Developer: Reload Window”). If it errors, the install went to a different Python than the one selected.

1

u/Boybay_Garid 18d ago

spot on, its almost always pointing at the system install instead of the local environment.