报错:Traceback (most recent call last): File "D:\devtools\python\lib\site-packages\pandas\compat\_optional.py", line 135, in import_optional_dependency module = importlib.import_module(name) File "D:\devtools\python\lib\importlib\__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1050, in _gcd_import File "<frozen importlib._bootstrap>", line 1027, in _find_and_load File "<frozen importlib._bootstrap>", line 1004, in _find_and_load_unlocked ModuleNotFoundError: No module named 'openpyxl' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "D:\pycharmproject\pythonProject\1.py", line 8, in <module> df = pd.read_excel('E:\Data.xlsx') File "D:\devtools\python\lib\site-packages\pandas\io\excel\_base.py", line 495, in read_excel io = ExcelFile( File "D:\devtools\python\lib\site-packages\pandas\io\excel\_base.py", line 1567, in __init__ self._reader = self._engines[engine]( File "D:\devtools\python\lib\site-packages\pandas\io\excel\_openpyxl.py", line 552, in __init__ import_optional_dependency("openpyxl") File "D:\devtools\python\lib\site-packages\pandas\compat\_optional.py", line 138, in import_optional_dependency raise ImportError(msg) ImportError: Missing optional dependency 'openpyxl'. Use pip or conda to install openpyxl.
应该如何解决
这个错误信息表明你的Python环境中缺少名为openpyxl
的模块,这个模块是Pandas用来读取Excel文件(特别是.xlsx
格式)的依赖库。要解决这个问题,你需要安装openpyxl
模块。
直接使用
pip install openpyxl
用语句pip show openpyxl查看是否成功
标签:机器,openpyxl,py,学习,报错,File,import,line,optional From: https://www.cnblogs.com/yuanxinglan/p/18617830