一、网络超时(Connection timeout)
- 解决办法:
- 更换国内镜像源:pip install 包名 -i https://pypi.tuna.tsinghua.edu.cn/simple
- 检查网络代理,关闭 VPN 或调整代理配置
- 增加超时时间:pip install 包名 –default-timeout=100
二、找不到指定版本(Could not find a version that satisfies the requirement)
- 解决办法:
- 查看 PyPI 官网确认包的有效版本,指定版本安装:pip install 包名==x.y.z
- 升级 pip:pip install –upgrade pip
- 检查包名是否拼写错误(如python-dateutil vs pythondateutil)
三、权限不足(Permission denied)
- 解决办法:
- 管理员权限安装(Windows:cmd 以管理员运行;Linux/macOS:sudo pip install 包名)
- 使用虚拟环境避免全局权限问题:python -m venv venv → 激活虚拟环境后再安装
四、编译失败(如Microsoft Visual C++ 14.0 is required)
- 解决办法:
- Windows:安装对应版本的 Visual C++ 构建工具(官网下载)
- Linux:安装系统依赖:sudo apt-get install python3-dev gcc g++
- macOS:安装 Xcode 命令行工具:xcode-select –install
五、缓存损坏(Corrupted package cache)
- 解决办法:
- 清理 pip 缓存:pip cache purge
- 删除缓存目录后重试(Windows:%LocalAppData%\pip\cache;Linux/macOS:~/.cache/pip)
