Install openpyxl into the same Python environment that runs your script. For most projects, create a virtual environment, activate it, then run python -m pip install openpyxl. If Python still reports ModuleNotFoundError: No module named 'openpyxl', check which interpreter your script, IDE, or notebook is actually using.
How do I install openpyxl?
The most reliable approach is to install the package in a project virtual environment. Python’s module installation guide describes venv as its standard tool for creating virtual environments, and the openpyxl installation guide advises using a virtual environment without system packages.
- Create an environment in your project directory: run
python -m venv .venv. - Activate it: in macOS or Linux shells, run
source .venv/bin/activate. In Windows PowerShell, run.venvScriptsActivate.ps1. In Windows Command Prompt, run.venvScriptsactivate.bat. - Install openpyxl: run
python -m pip install openpyxl. - Verify the package and import: run
python -c "import openpyxl; print(openpyxl.__version__)". You can also start Python in that environment and tryfrom openpyxl import Workbook.
Using python -m pip runs pip through the selected Python interpreter, rather than relying on a separate pip command that might belong to another installation. If you need a specific Python version, use its matching launcher: for example, python3.14 -m pip install openpyxl on a POSIX system, or py -3.14 -m pip install openpyxl on Windows. Replace 3.14 with the version you intend to use; the available command depends on how Python is installed.
Choose where to install the package
A virtual environment is a good default for a project because it keeps that project’s packages separate. You can also install into an existing interpreter or use a per-user installation when appropriate. Whichever option you choose, the application that runs your code must use the interpreter where openpyxl was installed.
#1 Best Overall
| Option | Package isolation | System-Python considerations | Key check |
|---|---|---|---|
| Project virtual environment | Packages are kept in the project’s environment. | Avoids changing the system Python’s package set. | Run the project with the environment’s interpreter. |
| Existing interpreter or per-user install | Packages share that interpreter or user site rather than a project-only environment. | Check whether the interpreter is managed by an operating system or another tool; Python warns that pip changes to a Linux distribution’s system Python can conflict with its package manager. | Confirm the target application uses that same interpreter. |
Activation is convenient but not required. Python documents that a virtual environment has its own package directories, and you can invoke its interpreter directly. For example, from a project directory, run .venv/bin/python -m pip install openpyxl on macOS or Linux, or .venvScriptspython.exe -m pip install openpyxl on Windows.
Why do I get ModuleNotFoundError: No module named 'openpyxl' after installing it?
The usual thing to check is whether installation and execution used different Python interpreters. A successful pip installation only confirms that the package was installed in the environment targeted by that pip command. An IDE, notebook kernel, scheduled task, or another terminal can run a different interpreter.
Rank #2
- Install through the intended interpreter: use
python -m pip install openpyxlin the environment that will run the script. - Check package metadata in that environment: run
python -m pip show openpyxlfrom the same shell. This helps confirm which interpreter’s pip can see the package. - Run the import test where the error occurs: test from the IDE, notebook kernel, or runtime that executes your code—not only from a different terminal.
- Select the project environment in your application: if an IDE or notebook uses another interpreter or kernel, point it to the project environment’s Python executable.
If you do not know which interpreter is being used, collect the exact install command, the command or application that runs the script, and the complete traceback. Those details are needed to distinguish an environment mismatch from another cause.
What if pip is missing or installation is blocked?
Python reports that pip is unavailable
Python’s installation guide lists python -m ensurepip --default-pip as one possible way to install pip. Whether it is available can depend on how Python was installed. Afterward, use python -m pip with the interpreter intended for your project.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Scan for outdated or missing drivers - takes under a minute3Repair Windows errors before they cause bigger problemsThe interpreter is managed by the system
Do not assume that installing into a protected system interpreter is the right fix. Python warns that pip changes to a Linux distribution’s system Python can interfere with the distribution package manager. A project virtual environment avoids changing that system package set; a per-user install may also be appropriate in some setups.
What if the import works but opening a workbook fails?
If import openpyxl succeeds and an error occurs later at load_workbook(), Python has found the package. Investigate the workbook and the full traceback instead of reinstalling the package as the first response. The openpyxl documentation says the library follows OOXML and can reject invalid workbooks, so a workbook-format problem is distinct from a missing-module error.
Do Pillow or lxml need to be installed?
No, neither is required for an ordinary openpyxl import or basic workbook creation. The documentation says Pillow is needed when embedding images in a workbook and can be installed separately with pip install pillow. It describes lxml as optional support that can be useful for creating large files.
For file-format scope, openpyxl’s project overview describes reading and writing Excel 2010 OOXML formats including .xlsx, .xlsm, .xltx, and .xltm. It does not support every Excel feature; its tutorial warns that shapes may be lost when an existing file is opened and saved.
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




