
Folgende Fehlermeldung erhielt ich, als ich in Python mittels Pandas eine Excel .xlsx Datei öffnen wollte:
# pandas.read_excel(r'c:\test.xlsx')
Exception has occurred: ImportError
Missing optional dependency 'openpyxl'. Use pip or conda to install openpyxl.
ModuleNotFoundError: No module named 'openpyxl'
During handling of the above exception, another exception occurred:
File "C:\test.py", line 5, in <module>
newData=pds.read_excel(file,sheet_name='Sheet1')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ImportError: Missing optional dependency 'openpyxl'. Use pip or conda to install openpyxl.
Installierte Python und Pandas Versionen sind:
# py -3 --version
Python 3.11.3
# pip freeze | findstr pandas
pandas==2.0.1
Nach etwas Recherche und lesen der Pandas Docs, ist es wie folgt:
It is strongly encouraged to install openpyxl to read Excel 2007+ (.xlsx) files. Please do not report issues when using ``xlrd`` to read ``.xlsx`` files. This is no longer supported, switch to using openpyxl instead.
Also openpyxl installieren:
# pip install openpyxl
# Collecting openpyxl
Downloading openpyxl-3.1.2-py2.py3-none-any.whl (249 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 250.0/250.0 kB 1.5 MB/s eta 0:00:00
Collecting et-xmlfile
Downloading et_xmlfile-1.1.0-py3-none-any.whl (4.7 kB)
Installing collected packages: et-xmlfile, openpyxl
Successfully installed et-xmlfile-1.1.0 openpyxl-3.1.2
[notice] A new release of pip available: 22.3.1 -> 23.1.2
[notice] To update, run: python.exe -m pip install --upgrade pip
Danach hat dann auch das einlesen der Excel xlsx funktioniert.
Quelle: https://pandas.pydata.org/docs/user_guide/io.html#excel-files
Thats it … Have Fun!