无法通过Anaconda更新OpenPyXL至3.1.0及以上版本的技术求助
解决Pandas要求openpyxl≥3.1.0但Anaconda仓库版本滞后的问题
错误信息
ImportError Traceback (most recent call last) Cell In[27], line 1 ----> 1 message_data = (pd.read_excel('message_types.xlsx', 2 sheet_name='messages') 3 .sort_values('id') 4 .drop('id', axis=1)) File c:\PATH.py:495, in read_excel(io, sheet_name, header, names, index_col, usecols, dtype, engine, converters, true_values, false_values, skiprows, nrows, na_values, keep_default_na, na_filter, verbose, parse_dates, date_parser, date_format, thousands, decimal, comment, skipfooter, storage_options, dtype_backend, engine_kwargs) 493 if not isinstance(io, ExcelFile): 494 should_close = True ---> 495 io = ExcelFile( 496 io, 497 storage_options=storage_options, 498 engine=engine, 499 engine_kwargs=engine_kwargs, 500 ) 501 elif engine and engine != io.engine: 502 raise ValueError( 503 "Engine should not be specified when passing " 504 "an ExcelFile - ExcelFile already has the engine set" 505 ) File c:\PATH.py:1567, in ExcelFile.__init__(self, path_or_buffer, engine, storage_options, engine_kwargs) 1564 self.engine = engine ... ---> 164 raise ImportError(msg) 165 else: 166 return None ImportError: Pandas requires version '3.1.0' or newer of 'openpyxl' (version '3.0.10' currently installed).
问题原因
Anaconda默认的conda包仓库中,openpyxl的版本更新速度慢于官方发布版本,导致导航器显示的最新版本停留在3.0.10,无法满足Pandas的版本要求。
解决方法
方法1:使用pip安装最新版
激活你当前使用的Anaconda环境后,执行以下命令:
pip install --upgrade openpyxl
方法2:通过conda-forge仓库安装
conda-forge社区维护的包更新更及时,步骤如下:
- 添加conda-forge仓库:
conda config --add channels conda-forge
- 设置conda-forge仓库优先级高于默认仓库:
conda config --set channel_priority strict
- 安装/更新openpyxl:
conda install openpyxl
验证安装结果
打开Python终端,执行以下代码确认版本:
import openpyxl print(openpyxl.__version__)
输出版本号≥3.1.0即为成功。
内容的提问来源于stack exchange,提问作者LetsGetTr0pical
相关产品推荐
相关产品推荐

