python - 即使安装了“openpyxl”也无法读取 xlsx 文件
问题描述
我想将 .xls 和 .xlsx 文件都读取到数据帧中,根据互联网上的内容,我的系统中应该安装包 ['xlrd' 和 'openpyxl']
我的系统是MAC,独立安装了[python和Jupyter lab],也安装了[Anaconda],我可以从终端或Anaconda浏览器运行Jupyter Lan。
安装“xlrd”后,我可以毫无问题地读取 .xls 文件。
但在安装“openpyxl”并尝试读取 .xlsx 文件后,出现以下错误:
我试图卸载并重新安装 openpyxl 但仍然存在同样的问题。
同时我检查了openpyxl的两个安装,在Anaconda它是v3.0.5,在python它是v3.0.6
这是正常的吗??
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-11-f15b3a520ce0> in <module>
1 ### 1.2 : Load Sciamgo Jurnal Excel file with xlsx format
----> 2 xlsx = pd.ExcelFile('assets/scimagojr-3.xlsx', engine='openpyxl')
3 sciamgo = pd.read_excel(xlsx)
4
5
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/io/excel/_base.py in __init__(self, io, engine)
822 self._io = stringify_path(io)
823
--> 824 self._reader = self._engines[engine](self._io)
825
826 def __fspath__(self):
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/io/excel/_openpyxl.py in __init__(self, filepath_or_buffer)
482 Object to be parsed.
483 """
--> 484 import_optional_dependency("openpyxl")
485 super().__init__(filepath_or_buffer)
486
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/compat/_optional.py in import_optional_dependency(name, extra, raise_on_missing, on_version)
90 except ImportError:
91 if raise_on_missing:
---> 92 raise ImportError(msg) from None
93 else:
94 return None
ImportError: Missing optional dependency 'openpyxl'. Use pip or conda to install openpyxl.
解决方案
推荐阅读
- javascript - 如何从 json 数据加载多个图像 - django
- mql4 - MQL4 中 BackTest 中的 ComboBox 更改值
- c - 现代 C 标准中是否有 nullptr (或等效项)之类的东西?
- flutter - 在 Flutter 中阻止部分 Slider Widget
- python - 创建新的空 GeoDataFrame 的语法
- javascript - 在 N 个区间内拆分最小值和最大值的范围
- typescript - 动态获取对象属性的类型
- r - 使用 R Bloomberg API 下载期权链
- javascript - WPForms - 更改总值
- delphi - 针对之前在 Delphi 中保存的 TADODataSet 运行 SQL TADOQuery