Python Forum
"openpyxl" is not accessed Pylance
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
"openpyxl" is not accessed Pylance
#1
Hello,

I installed openpyxl using pip install openpyxl, but I’m running into issues when trying to use it.

In my script, import openpyxl is flagged by Pylance as "openpyxl is not accessed". When I run the script, I get the following error:
ModuleNotFoundError: No module named 'openpyxl'

Please advise.
Thanks.
Dee
Reply
#2
ModuleNotFoundError: No module named 'openpyxl'
That usually means openpyxl was installed into a different Python environment than the one running your script.
I you use VS Code look down i right corner to see what Python interpreter it use or
Ctrl + Shift + P
Then type:
Python: Select Interpreter

From command line,if work here use same Python interpreter in VC Code.
python -m pip install openpyxl

python --version
python -c "import sys; print(sys.executable)"

python -m pip show openpyxl
python -c "import openpyxl; print(openpyxl.__version__)"
Reply
#3
Are you using a virtual environment? If so, did you activate your virtual environment before running "pip install openpyxl"? Does openpyxl appear in the list when you run "pip list"?
Reply
#4
Thanks for the responses.

openpyxl was installed. After I ran "-m pip show openpyxl", it has the following. It seems for Excel 2010.
Version: 3.1.5
Summary: A Python library to read/write Excel 2010 xlsx/xlsm files
Home-page: https://openpyxl.readthedocs.io
Author: See AUTHORS
Author-email: [email protected]
License: MIT
Location: C:\****\.venv\Lib\site-packages
Requires: et-xmlfile

What if I have Excel 365?
Reply
#5
That shows that you have openpyxl installed in some virtual environment (****\.venv). Are you using that virtual environment when you run your program?
Reply
#6
Location: C:\****\.venv\Lib\site-packages
This mean that openpyxl is installed in a virtual environment.

Then you most choose this environment in VS Code.
Open Command Palette: Ctrl + Shift + P
Choose Python: Select Interpreter
Select the interpreter that points to environment:
C:\...\ .venv\Scripts\python.exe
Reply
#7
Thanks snippsat and deanhystad.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Pylance: "... is not a known attribute of module ..." ? MvGulik 5 3,663 Jul-08-2025, 04:41 PM
Last Post: MvGulik
  Check last time file was accessed Pavel_47 4 5,017 Jun-01-2021, 05:47 PM
Last Post: Yoriz
  Python linter Pylance: What does "(variable): List | Unbound" mean? Drone4four 1 9,844 Oct-23-2020, 08:31 PM
Last Post: bowlofred

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020