ImportError: Pandas requires version '3.0.7' or newer of 'openpyxl' (version '3.0.5' currently installed)

Question:

I have a strange problem which leads to the msg in the title, leading to the error report below.
The fact is – I have (on Linux) python 3.9.15, Pandas 1.5.2, openpyxl 3.0.10. I do not use venv, for editing I use Wing, but I do not run script from it, only from the shell.
I looked over /usr/lib64/python3.9/site-packages/ but did not find any other version of openpyxl laying around. What’s wrong? I even uninstalled and re-installed both pandas and openpyxl – no effect.

File "./elektreiba-00-02.py", line 140, in <module> main(sys.argv[1:])
  File "./elektreiba-00-02.py", line 79, in main  df = pd.read_excel(infile, sheet_name=None)
  File "/usr/lib64/python3.9/site-packages/pandas/util/_decorators.py", line 211, in wrapper
    return func(*args, **kwargs)
  File "/usr/lib64/python3.9/site-packages/pandas/util/_decorators.py", line 331, in wrapper
    return func(*args, **kwargs)
  File "/usr/lib64/python3.9/site-packages/pandas/io/excel/_base.py", line 482, in read_excel
    io = ExcelFile(io, storage_options=storage_options, engine=engine)
  File "/usr/lib64/python3.9/site-packages/pandas/io/excel/_base.py", line 1695, in __init__
    self._reader = self._engines[engine](self._io, storage_options=storage_options)
  File "/usr/lib64/python3.9/site-packages/pandas/io/excel/_openpyxl.py", line 556, in __init__
    import_optional_dependency("openpyxl")
  File "/usr/lib64/python3.9/site-packages/pandas/compat/_optional.py", line 171, in import_optional_dependency
    raise ImportError(msg)
ImportError: Pandas requires version '3.0.7' or newer of 'openpyxl' (version '3.0.5' currently installed)
Asked By: JanisE

||

Answers:

It turned out being cache question – no idea what created a site-package cache under ~/./local/ and why python looked there at first

Answered By: JanisE

Try to un-install the openpyxl:

pip uninstall openpyxl

And reinstall it:

pip install openpyxl

This will do the work

enter image description here

Answered By: Ravi kumar
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.