今天在用pip安装opencv-python时,pip install opencv-python后速度极其缓慢,几分钟后提示下载失败,并报错如下:
ERROR: Exception:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pip/_vendor/urllib3/response.py", line 437, in _error_catcher
yield
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pip/_vendor/urllib3/response.py", line 519, in read
data = self._fp.read(amt) if not fp_closed else b""
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 454, in read
n = self.readinto(b)
.................................................
中间略
..................................................
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/contextlib.py", line 131, in __exit__
self.gen.throw(type, value, traceback)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pip/_vendor/urllib3/response.py", line 442, in _error_catcher
raise ReadTimeoutError(self._pool, None, "Read timed out.")
pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.
报错原因:
一开始没用弄清楚问题的原因,就盲目搜素了各种办法去解决,比如在命令前边加sudo,但都没有解决,后来找到了根源才知道这个报错是什么意思,感觉自己像个憨憨一样。
⚠️原来这种报错是因为下载外网资源网速太慢了!!
解决办法:
只需切换到国内安装镜像即可,这里我用的是清华的镜像:
pip install opencv-python -i https://pypi.tuna.tsinghua.edu.cn/simple
安装完打开pycharm验证一下,输入代码运行程序:
import cv2
print(cv2.__version__)
不报错并输出opencv版本:
安装成功✌️