Fix: ModuleNotFoundError No module named openpyxl


Error trace:
% python3 data_script.py
 
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pandas/compat/_optional.py", line 142, in import_optional_dependency
    module = importlib.import_module(name)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1140, in _find_and_load_unlocked

ModuleNotFoundError: No module named 'openpyxl'

During the handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/c2ctech/Desktop/example.py", line 5, in <module>
    dataframe = pd.read_excel(excel_file)

If you are trying to execute a Python code that makes use of the pandas' module and has a method that deals with Excel files with extensions like .xlsx or .xls, you will get an error "ModuleNotFoundError: No module named 'openpyxl'" then you have missed to install openpyxl module that's needed to work with Excel files.

Fix - ModuleNotFoundError - No module named openpyxl

Fix: ModuleNotFoundError: No module named 'openpyxl'

    Option 1: If you are using pip/pip3

      pip install openpyxl

      pip3 install openpyxl

    Option 12 If you are using conda/miniconda

      conda install openpyxl

-

Facing issues? Have Questions? Post them here! I am happy to answer!


Author: Rakesh
Author Info:

Rakesh is a seasoned developer with over 10 years of experience in web and app development, and a deep knowledge of operating systems. Author of insightful How-To articles for Code2care.

Follow him on: X

Copyright © Code2care 2023 | Privacy Policy | About Us | Contact Us | Sitemap