Every programming language encounters many errors. Some occur at the compile time, some at run time.
This article will discuss Python’s
No module named 'openpyxl' error. A
ModuleNotFoundError arises when the module we are importing is not installed or is located in another directory.
Openpyxl is a library in Python that reads and writes data from an Excel file.
Causes of the
No module named 'openpyxl' Error in Python
Module Not Installed
The most common cause of this error is that the module
openpyxl is not installed, and we are trying to import it into our program.
To fix this error, we need to install the module correctly. If we use Anaconda, we will use the following command to install the
#Python 3.x conda install -c anaconda openpyxl
If we are not using Anaconda, we can use the
pip command to install the
If we are using Python 2, use the following command.
#Python 2.x (Windows) pip install openpyxl
If we are using Python 3, use the following command.
#Python 3.x (Windows) pip3 install openpyxl
pip is not set in your
PATH environment variable:
python -m pip install openpyxl
yum install openpyxl
sudo apt-get install openpyxl
The error can also arise if we install the
pip if you are using Python 3 and vice versa. We should install the
openpyxl using the correct
We will use the following command to check whether the
openpyxl module is installed successfully.
#Python 3.x pip list
It will show us the list of installed modules. If we find the
openpyxl module in the list, it is installed successfully.
Incorrect Module Path
If the module is installed correctly, but we still face the error, the module and our Python code are located in different directories.
For example, the directory structure looks like the following.
code.py my_folder ---module.py
In this case, we can solve the error by correctly importing the module from the other directory using the following syntax.
#Python 3.x import my_folder.module.py
- Can Only Concatenate List (Not Int) to List in Python
- Invalid Syntax in Python
- Value Error Need More Than One Value to Unpack in Python
- ValueError Arrays Must All Be the Same Length in Python
- Fix the TypeError: Object of Type 'Int64' Is Not JSON Serializable
- Fix the TypeError: 'float' Object Cannot Be Interpreted as an Integer in Python