Python3.7安装matplotlib模块的时候报错During handling of the above exception, another exception occurred:

安装matplotlib模块,网上的办法大都是直接在cmd中安装,三个步骤就可安装完成:
1.win+R 输入cmd 进入命令提示符
2.输入 python -m pip install -U pip setuptools 进行升级。
3.输入python -m pip install matplotlib安装matplotlib模块
4.然后输入python -m pip list ,查看Python所有已经安装的包,看matplotlib是否已安装
但是我一直运行不成功,提示的错误信息为:

PS C:\Users\ASUS\AppData\Local\Programs\Python\Python37> python -m pip install matplotlib
Collecting pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1
  Downloading pyparsing-2.4.6-py2.py3-none-any.whl (67 kB)
     |██████████                      | 20 kB 1.4 kB/s eta 0:00:33ERROR: Exception:
Traceback (most recent call last):
  File "c:\users\asus\appdata\local\programs\python\python37\lib\site-packages\pip\_vendor\urllib3\response.py", line 425, in _error_catcher
    yield
  File "c:\users\asus\appdata\local\programs\python\python37\lib\site-packages\pip\_vendor\urllib3\response.py", line 507, in read
    data = self._fp.read(amt) if not fp_closed else b""
  File "c:\users\asus\appdata\local\programs\python\python37\lib\site-packages\pip\_vendor\cachecontrol\filewrapper.py", line 62, in read
    data = self.__fp.read(amt)
  File "c:\users\asus\appdata\local\programs\python\python37\lib\http\client.py", line 447, in read
    n = self.readinto(b)
  File "c:\users\asus\appdata\local\programs\python\python37\lib\http\client.py", line 491, in readinto
    n = self.fp.readinto(b)
  File "c:\users\asus\appdata\local\programs\python\python37\lib\socket.py", line 589, in readinto
    return self._sock.recv_into(b)
  File "c:\users\asus\appdata\local\programs\python\python37\lib\ssl.py", line 1049, in recv_into
    return self.read(nbytes, buffer)
  File "c:\users\asus\appdata\local\programs\python\python37\lib\ssl.py", line 908, in read
    return self._sslobj.read(len, buffer)
socket.timeout: The read operation timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\users\asus\appdata\local\programs\python\python37\lib\site-packages\pip\_internal\cli\base_command.py", line 186, in _main
    status = self.run(options, args)
  File "c:\users\asus\appdata\local\programs\python\python37\lib\site-packages\pip\_internal\commands\install.py", line 331, in run
    resolver.resolve(requirement_set)
  File "c:\users\asus\appdata\local\programs\python\python37\lib\site-packages\pip\_internal\legacy_resolve.py", line 177, in resolve
    discovered_reqs.extend(self._resolve_one(requirement_set, req))
  File "c:\users\asus\appdata\local\programs\python\python37\lib\site-packages\pip\_internal\legacy_resolve.py", line 333, in _resolve_one
    abstract_dist = self._get_abstract_dist_for(req_to_install)
  File "c:\users\asus\appdata\local\programs\python\python37\lib\site-packages\pip\_internal\legacy_resolve.py", line 282, in _get_abstract_dist_for
    abstract_dist = self.preparer.prepare_linked_requirement(req)
  File "c:\users\asus\appdata\local\programs\python\python37\lib\site-packages\pip\_internal\operations\prepare.py", line 482, in prepare_linked_requirement
    hashes=hashes,
  File "c:\users\asus\appdata\local\programs\python\python37\lib\site-packages\pip\_internal\operations\prepare.py", line 287, in unpack_url
    hashes=hashes,
  File "c:\users\asus\appdata\local\programs\python\python37\lib\site-packages\pip\_internal\operations\prepare.py", line 159, in unpack_http_url
    link, downloader, temp_dir.path, hashes
  File "c:\users\asus\appdata\local\programs\python\python37\lib\site-packages\pip\_internal\operations\prepare.py", line 303, in _download_http_url
    for chunk in download.chunks:
  File "c:\users\asus\appdata\local\programs\python\python37\lib\site-packages\pip\_internal\utils\ui.py", line 160, in iter
    for x in it:
  File "c:\users\asus\appdata\local\programs\python\python37\lib\site-packages\pip\_internal\network\utils.py", line 39, in response_chunks
    decode_content=False,
  File "c:\users\asus\appdata\local\programs\python\python37\lib\site-packages\pip\_vendor\urllib3\response.py", line 564, in stream
    data = self.read(amt=amt, decode_content=decode_content)
  File "c:\users\asus\appdata\local\programs\python\python37\lib\site-packages\pip\_vendor\urllib3\response.py", line 529, in read
    raise IncompleteRead(self._fp_bytes_read, self.length_remaining)
  File "c:\users\asus\appdata\local\programs\python\python37\lib\contextlib.py", line 130, in __exit__
    self.gen.throw(type, value, traceback)
  File "c:\users\asus\appdata\local\programs\python\python37\lib\site-packages\pip\_vendor\urllib3\response.py", line 430, 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.

尝试了很多次,都没有成功,后来找到了另一种办法,离线安装。在官网上下载matplotlib的安装包,放在电脑上的文件夹中,以下为例:
Python3.7安装matplotlib模块的时候报错During handling of the above exception, another exception occurred:_第1张图片
在文件空白处shift+鼠标右键,在此处打开powershell窗口
Python3.7安装matplotlib模块的时候报错During handling of the above exception, another exception occurred:_第2张图片
然后在命令窗口中输入pip install matplotlib-2.2.3-cp37-cp37m-win_amd64.whl(把下载的安装包全称复制过来即可),但还是报错。。。
Python3.7安装matplotlib模块的时候报错During handling of the above exception, another exception occurred:_第3张图片
又试了好几遍,有的时候感觉马上就成功了,结果还是错。。。
Python3.7安装matplotlib模块的时候报错During handling of the above exception, another exception occurred:_第4张图片
以及
Python3.7安装matplotlib模块的时候报错During handling of the above exception, another exception occurred:_第5张图片
快要放弃的我抱着最后的希望,在cmd中又试着安装了一遍,竟然轻而易举的成功了!而且只用了几秒时间。。。命运总是这么爱捉弄人。
具体做法:先进入我们下载的离线安装包的路径下,语法为:cd 路径
然后在这个路径下安装离线包:pip install matplotlib-2.2.3-cp37-cp37m-win_amd64.whl
最终输入:pip list确认是否安装成功。
Python3.7安装matplotlib模块的时候报错During handling of the above exception, another exception occurred:_第6张图片
总结:我记得当时搜相关博文的时候,有一个博主说他安装的时候报错是因为网络原因。我不知道我的算不算,感觉有点这个原因,但又觉得不像,很奇怪。。。如果跟我遇到相同问题的小伙伴可以试一下我的这个方法,希望对你有所帮助,我们一起交流讨论哇~。

你可能感兴趣的:(python)