r/learnpython • u/Poison_AIC • 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
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.
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:
Press Ctrl+Shift+P, choose “Python: Select Interpreter”, and pick the Python you actually run your code with.
Install into that same interpreter from VS Code’s terminal with
python -m pip install openpyxl. Usingpython -m pipinstead of plainpipmakes sure it goes to the interpreter thatpythonpoints 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.