今天在安装Python模块matplotlib的时候,一直安装不成功,老是提示“socket.timeout: The read operation timed out”或者“Read timed out.”

因为国内的网络访问国外延迟很高,所以安装模块很慢就不说了,还一定安装不上。

 [root@localhosts ~]# pip3 install --user matplotlib
WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead.
Collecting matplotlib
Downloading https://files.pythonhosted.org/packages/57/4f/dd381ecf6c6ab9bcdaa8ea912e866dedc6e696756156d8ecc087e20817e2/matplotlib-3.1.1-cp36-cp36m-manylinux1_x86_64.whl (13.1MB)
38% |████████████▍ | 5.1MB 11kB/s eta 0:12:11Exception:
Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/pip/_vendor/urllib3/response.py", line 302, in _error_catcher
yield
File "/usr/lib/python3.6/site-packages/pip/_vendor/urllib3/response.py", line 384, in read
data = self._fp.read(amt)
File "/usr/lib/python3.6/site-packages/pip/_vendor/cachecontrol/filewrapper.py", line 60, in read
data = self.__fp.read(amt)
File "/usr/lib64/python3.6/http/client.py", line 459, in read
n = self.readinto(b)
File "/usr/lib64/python3.6/http/client.py", line 503, in readinto
n = self.fp.readinto(b)
File "/usr/lib64/python3.6/socket.py", line 586, in readinto
return self._sock.recv_into(b)
File "/usr/lib64/python3.6/ssl.py", line 968, in recv_into
return self.read(nbytes, buffer)
File "/usr/lib64/python3.6/ssl.py", line 830, in read
return self._sslobj.read(len, buffer)
File "/usr/lib64/python3.6/ssl.py", line 587, in read
v = self._sslobj.read(len, buffer)
socket.timeout: The read operation timed out

这种情况可以使用国内的镜像源加速来安装

可以在pip后面添加-i参数,来指定安装源,这里我使用的是阿里云的安装源

 [root@localhosts ~]# pip3 install --user matplotlib -i http://mirrors.aliyun.com/pypi/simple --trusted-host mirrors.aliyun.com
Collecting matplotlib
Downloading http://mirrors.aliyun.com/pypi/packages/57/4f/dd381ecf6c6ab9bcdaa8ea912e866dedc6e696756156d8ecc087e20817e2/matplotlib-3.1.1-cp36-cp36m-manylinux1_x86_64.whl (13.1MB)
100% |████████████████████████████████| 13.1MB 12.5MB/s
Collecting pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 (from matplotlib)
Downloading http://mirrors.aliyun.com/pypi/packages/a3/c4/7828cf9e71ce8fbd43c1e502f3fdd0498f069fcf9d1c268205ce278ae201/pyparsing-2.4.4-py2.py3-none-any.whl (67kB)
100% |████████████████████████████████| 71kB 15.9MB/s
Collecting cycler>=0.10 (from matplotlib)
Downloading http://mirrors.aliyun.com/pypi/packages/f7/d2/e07d3ebb2bd7af696440ce7e754c59dd546ffe1bbe732c8ab68b9c834e61/cycler-0.10.0-py2.py3-none-any.whl
Collecting numpy>=1.11 (from matplotlib)
Downloading http://mirrors.aliyun.com/pypi/packages/0e/46/ae6773894f7eacf53308086287897ec568eac9768918d913d5b9d366c5db/numpy-1.17.3-cp36-cp36m-manylinux1_x86_64.whl (20.0MB)
100% |████████████████████████████████| 20.0MB 12.1MB/s
Collecting kiwisolver>=1.0.1 (from matplotlib)
Downloading http://mirrors.aliyun.com/pypi/packages/f8/a1/5742b56282449b1c0968197f63eae486eca2c35dcd334bab75ad524e0de1/kiwisolver-1.1.0-cp36-cp36m-manylinux1_x86_64.whl (90kB)
100% |████████████████████████████████| 92kB 15.7MB/s
Collecting python-dateutil>=2.1 (from matplotlib)
Downloading http://mirrors.aliyun.com/pypi/packages/d4/70/d60450c3dd48ef87586924207ae8907090de0b306af2bce5d134d78615cb/python_dateutil-2.8.1-py2.py3-none-any.whl (227kB)
100% |████████████████████████████████| 235kB 12.5MB/s
Requirement already satisfied: six in ./.local/lib/python3.6/site-packages (from cycler>=0.10->matplotlib)
Requirement already satisfied: setuptools in /usr/lib/python3.6/site-packages (from kiwisolver>=1.0.1->matplotlib)
Installing collected packages: pyparsing, cycler, numpy, kiwisolver, python-dateutil, matplotlib
Successfully installed cycler-0.10.0 kiwisolver-1.1.0 matplotlib-3.1.1 numpy-1.17.3 pyparsing-2.4.4 python-dateutil-2.8.1
04-17 01:09
查看更多