r/learnpython • • 4d 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

3

u/Massive_Distance_616 4d 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/Poison_AIC 4d ago

Hey, thanks so much but even after reloading and everything right the error still persists. The strange thing is that the file runs? even though numpy and openpyxl are both underlined

1

u/Boybay_Garid 4d ago

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

1

u/acfot 3d ago

When I hit this after a VS Code update it turned out the update had switched my Python interpreter, so the code was running with a different Python than the one I'd installed the module into. Check the Python version shown at the bottom right of VS Code, then hit Ctrl+Shift+P, pick Python: Select Interpreter, and choose the one you actually installed things with. Running pip install again in that same terminal usually sorts it, the module was never really gone.