pip install pandas卡在downloading是因为默认从国外pypi源下载,网络延迟高、易超时;解决方法是临时加国内镜像源,如pip install pandas -i https://pypi.tuna.tsinghua.edu.cn/simple/,必须带/simple/后缀,否则404。

为什么 pip install pandas 总是卡在 downloading?
因为默认从 PyPI 官方源(https://pypi.org/simple/)下载,服务器在国外,国内直连常出现超时、重试、速度低于 50KB/s 甚至中断。这不是 Pandas 本身的问题,而是网络链路导致的——你下载的其实是 pandas 及其依赖(numpy、pytz、python-dateutil 等)的 wheel 文件,单个文件常超 10MB。
临时换源:一条命令搞定当前安装
不改配置、不装工具,只针对这次 pip install pandas 加镜像参数:
pip install pandas -i https://pypi.tuna.tsinghua.edu.cn/simple/
或用阿里云源:
pip install pandas -i https://mirrors.aliyun.com/pypi/simple/
- 必须加
/simple/后缀,漏掉会 404 - 如果提示
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)),说明没生效,检查拼写和斜杠 - 清华源响应快但偶尔同步延迟(通常
永久配置:避免每次敲长命令
改的是 pip 的配置文件,不是 Python 或系统环境变量。不同系统路径不同,但逻辑一致:
- Windows:
%APPDATA%\pip\pip.ini(若不存在,新建) - macOS / Linux:
$HOME/.pip/pip.conf(目录和文件都需手动创建)
在该文件中写入:
[global] index-url = https://pypi.tuna.tsinghua.edu.cn/simple/ trusted-host = pypi.tuna.tsinghua.edu.cn
注意:trusted-host 必须写,否则 pip 会因 HTTPS 证书校验失败报错 Could not fetch URL ... There was a problem confirming the ssl certificate;如果换阿里源,对应改成 mirrors.aliyun.com。
验证是否生效 & 常见失效场景
运行 pip config list 应输出类似 global.index-url='https://pypi.tuna.tsinghua.edu.cn/simple/';再执行 pip install pandas --dry-run(不真装,只模拟),观察日志里下载域名是否已变成镜像站。
- 公司内网可能屏蔽外部镜像,表现为“连接超时”而非“速度慢”,此时需联系 IT 配置内部 PyPI 代理
- 某些 IDE(如 PyCharm)自带 pip 独立配置,它不读系统 pip.conf,得在 Settings → Project → Python Interpreter → ⚙️ → Show All → 选中解释器 → Show Console → 点击右上角 folder 图标,进去改它的 pip 配置
- 使用
python -m pip而非全局pip命令时,也走同一套配置,无需额外处理
镜像源只是加速手段,解决不了包本身兼容问题——比如你在 Python 3.13 上装旧版 pandas 仍会报 No matching distribution,那得换版本,不是换源能绕过的。
Python免费学习笔记(深入):立即使用
在学习笔记中,你将探索 Python 的核心概念和高级技巧!











