pip在安装包过程中出现如下错误,
Collecting grpcio==1.34.0
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f6f7311e310>: Failed to establish a new connection: [Errno 101] Network is unreachable')': /packages/45/dd/f87383954f1d9940db899eb69c72350c1065a4331b397f7da62f221867f2/grpcio-1.34.0-cp38-cp38-manylinux2014_x86_64.whl
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f6f7311e460>: Failed to establish a new connection: [Errno 101] Network is unreachable')': /packages/45/dd/f87383954f1d9940db899eb69c72350c1065a4331b397f7da62f221867f2/grpcio-1.34.0-cp38-cp38-manylinux2014_x86_64.whl
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f6f7311e5b0>: Failed to establish a new connection: [Errno 101] Network is unreachable')': /packages/45/dd/f87383954f1d9940db899eb69c72350c1065a4331b397f7da62f221867f2/grpcio-1.34.0-cp38-cp38-manylinux2014_x86_64.whl
此时可以通过如下两种方式解决:
- 针对单个包
pip3 install xxx -i https://pypi.tuna.tsinghua.edu.cn/simple/ --trusted-host pypi.tuna.tsinghua.edu.cn
- 全局修改
pip3 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
第1种方法可以用于单个包的安装。第二种方法用于整个项目或全局修改。