You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

为何无法将Pandas从2.2.0降级至1.5.3?

问题

我把Pandas升级到2.2.0版本后,因为需要使用.iteritems()方法,尝试用以下命令降级到1.5.3版本:

pip install pandas==1.5.3

但遇到编译错误:

Failed to build pandas
ERROR: Could not build wheels for pandas, which is required to install pyproject.toml-based projects

解决方法

1. 先卸载现有Pandas版本

彻底移除当前版本,避免版本冲突干扰安装:

pip uninstall -y pandas

2. 安装编译依赖(分系统操作)

Pandas 1.5.3编译需要依赖工具,根据你的系统安装对应组件:

  • Windows:安装Microsoft Visual C++ Build Tools,勾选「Desktop development with C++」组件完成安装。
  • macOS:先安装Xcode命令行工具:
    xcode-select --install
    
    再通过Homebrew安装依赖库:
    brew install openblas
    
  • Linux(Ubuntu/Debian):执行命令安装编译依赖包:
    sudo apt-get update && sudo apt-get install build-essential python3-dev python3-pip python3-setuptools gcc gfortran libopenblas-dev liblapack-dev
    

3. 直接安装预编译wheel包

跳过本地编译,强制使用PyPI上的预编译wheel文件:

pip install pandas==1.5.3 --only-binary :all:

也可以先升级pip,让它优先识别预编译包:

pip install --upgrade pip
pip install pandas==1.5.3

4. 检查Python版本兼容性

Pandas 1.5.3仅支持Python 3.8-3.10,若你使用3.11及以上版本,大概率会出现编译问题。可以用conda创建兼容的虚拟环境:

conda create -n pandas153 python=3.10
conda activate pandas153
pip install pandas==1.5.3

5. 替代方案:无需降级,替换方法

Pandas 2.0+中.iteritems()已被.items()替代,两者功能完全一致。直接把代码里的.iteritems()替换成.items(),即可不用降级正常使用。

内容的提问来源于stack exchange,提问作者Bhuvaneswari Bhuvaneswari

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 19:58:13