python-pip更改下载路径,解决超时问题

z67767707 / 2024-03-04 / 原文

有时pip安装包时,会提示

pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.

原因跟解决方式

PyPI镜像:考虑使用PyPI的镜像站点。中国用户经常遇到与files.pythonhosted.org的连接问题,因此他们经常使用清华大学的PyPI镜像。你可以设置pip使用镜像站点,例如:

bashpip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

设置后,pip会从这个镜像站点而不是默认的files.pythonhosted.org下载包。