Modulenotfounderror: no module named openpyxl error occurs when openpyxl module is either not installed or misconfigured with the system path. There are many situations where we install openpyxl in any virtual environment but run the application or code base in a different virtual environment or globally. Since the installed openpyxl is pointed with a different interpreter and not available in any other virtual environment. This time the currently selected interpreter will throw the same error. Anyways In this article, How can we install openpyxl differently and fix this modulenotfounderror.
modulenotfounderror: no module named openpyxl ( Solution ) –
We will install this openpyxl module with pip, conda, and source code. In each section, we will also try to cover the variation.
Method 1: pip for installation openpyxl –
Use this command to install openpyxl.
pip install openpyxl
We can specify the version detail along with the command to avoid compatibility issues if any with the latest version. Since the above one will install the latest stable version of openpyxl.
pip install openpyxl==3.0.9
If Admin privileges are required to run this command in Linux or a similar OS then add sudo keyword along with it. Also if you are on Windows-based OS then launch the cmd in admin mode and rerun the above command.
Method 2: conda for installation openpyxl –
If you have Anaconda installed in the system and you want to use conda ( default package manager ) then use the below command to install openpyxl.
conda install -c anaconda openpyxl
Method 3: Installation through source code –
In this step, we will first download the source code for openpyxl implementation in Python. Now we need to run –
python setup.py install
It will build the file locally and then we have to place it into site-packages folder before we import the package. It will fix the above error.
Data Science Learner Team
Join our list
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.