错误原因
pip安装依赖时出现报错:ConnectError: [WinError 10054] 远程主机强迫关闭了一个现有的连接。
这通常表示在尝试从 Python 包索引 (PyPI) 下载 python-docx 包时遇到了网络连接问题。
而默认的下载源在国外服务器上,所以连接常常不稳定。
解决方法
VPN
有时使用梯子也会因梯子不稳定而失败,所以最好的办法是切换国内镜像源↓
切换国内镜像源
- 如果你使用pdm,可以将 PDM 的 PyPI 镜像源配置为清华大学的镜像地址。
pdm config pypi.url https://pypi.tuna.tsinghua.edu.cn/simple
- 如果你使用pip,
pip config pypi.url https://pypi.tuna.tsinghua.edu.cn/simple
运行命令:pdm config 或者 pip config
pdm config
可见pypi.url = https://pypi.org/simple 一项变暗,
并且新增了:
Home configuration (C:\Users\hbche\AppData\Local\pdm\pdm\config.toml):
pypi.url = https://pypi.tuna.tsinghua.edu.cn/simple
本文由博客一文多发平台 OpenWrite 发布!