在VScode中安裝matplotlib的解决

在VScode中安装 matplotlib 是在终端中输入安装命令解决的。
初次安装的python版本是3.6.8, 自带的pip版本是19, 执行安装matplotlib命令时,提示pip 版本过低,无法继续安装。 后执行了pip的升级命令,依然无法成功。

后卸载python3.6.8,安装了3.11.

检查了pip版本:pip 22.3.1 from C:\Users\gym\AppData\Local\Programs\Python\Python311\Lib\site-packages\pip (python 3.11)

安装之前,仍然在VScode中做了更新,
python.exe -m pip install --upgrade pip

返回:Requirement already satisfied: pip in c:\users\gym\appdata\local\programs\python\python311\lib\site-packages (22.3.1)
WARNING: There was an error checking the latest version of pip.

后执行安装matplotlib:
python -m pip install --user matplotlib

返回:
*Collecting matplotlib
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘ConnectTimeoutError(, ‘Connection to files.pythonhosted.org timed out. (connect timeout=15)’)’: /packages/c5/96/40374f9d6f28966ed5ba00c0442ded12cfa2ad17c0c4a4ccd26191d1ecde/matplotlib-3.6.2-cp311-cp311-win_amd64.whl
Downloading matplotlib-3.6.2-cp311-cp311-win_amd64.whl (7.2 MB)
╸━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 0.2/7.2 MB 17.7 kB/s eta 0:06:40
ERROR: Exception:
Traceback (most recent call last):
File “C:\Users\gym\AppData\Local\Programs\Python\Python311\Lib\site-packages\pip_vendor\urllib3\response.py”, line 437, in _error_catcher
yield
File “C:\Users\gym\AppData\Local\Programs\Python\Python311\Lib\site-packages\pip_vendor\urllib3\response.py”, line 560, in read
data = self._fp_read(amt) if not fp_closed else b""
^^^^^^^^^^^^^^^^^^
File “C:\Users\gym\AppData\Local\Programs\Python\Python311\Lib\site-packages\pip_vendor\urllib3\response.py”, line 526, in _fp_read
return self._fp.read(amt) if amt is not None else self._fp.read()
^^^^^^^^^^^^^^^^^^
File “C:\Users\gym\AppData\Local\Programs\Python\Python311\Lib\site-packages\pip_vendor\cachecontrol\filewrapper.py”, line 90, in read
data = self.__fp.read(amt)
^^^^^^^^^^^^^^^^^^^
File “C:\Users\gym\AppData\Local\Programs\Python\Python311\Lib\http\client.py”, line 465, in read
s = self.fp.read(amt)
^^^^^^^^^^^^^^^^^
File “C:\Users\gym\AppData\Local\Programs\Python\Python311\Lib\socket.py”, line 706, in readinto
return self._sock.recv_into(b)
^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\gym\AppData\Local\Programs\Python\Python311\Lib\ssl.py”, line 1278, in recv_into
return self.read(nbytes, buffer)
^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\gym\AppData\Local\Programs\Python\Python311\Lib\ssl.py”, line 1134, in read
return self._sslobj.read(len, buffer)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TimeoutError: The read operation timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “C:\Users\gym\AppData\Local\Programs\Python\Python311\Lib\site-packages\pip_internal\cli\base_command.py”, line 160, in exc_logging_wrapper
status = run_func(args)
^^^^^^^^^^^^^^^
File “C:\Users\gym\AppData\Local\Programs\Python\Python311\Lib\site-packages\pip_internal\cli\req_command.py”, line 247, in wrapper
return func(self, options, args)
^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\gym\AppData\Local\Programs\Python\Python311\Lib\site-packages\pip_internal\commands\install.py”, line 400, in run
requirement_set = resolver.resolve(
^^^^^^^^^^^^^^^^^
File “C:\Users\gym\AppData\Local\Programs\Python\Python311\Lib\site-packages\pip_internal\resolution\resolvelib\resolver.py”, line 92, in resolve
result = self._result = resolver.resolve(
^^^^^^^^^^^^^^^^^
File “C:\Users\gym\AppData\Local\Programs\Python\Python311\Lib\site-packages\pip_vendor\resolvelib\resolvers.py”, line 481, in resolve
state = resolution.resolve(requirements, max_rounds=max_rounds)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\gym\AppData\Local\Programs\Python\Python311\Lib\site-packages\pip_vendor\resolvelib\resolvers.py”, line 348, in resolve
self._add_to_criteria(self.state.criteria, r, parent=None)
File “C:\Users\gym\AppData\Local\Programs\Python\Python311\Lib\site-packages\pip_vendor\resolvelib\resolvers.py”, line 172, in _add_to_criteria
if not criterion.candidates:
File “C:\Users\gym\AppData\Local\Programs\Python\Python311\Lib\site-packages\pip_vendor\resolvelib\structs.py”, line 151, in bool
return bool(self._sequence)
^^^^^^^^^^^^^^^^^^^^
File “C:\Users\gym\AppData\Local\Programs\Python\Python311\Lib\site-packages\pip_internal\resolution\resolvelib\found_candidates.py”, line 155, in bool
return any(self)
^^^^^^^^^
File “C:\Users\gym\AppData\Local\Programs\Python\Python311\Lib\site-packages\pip_internal\resolution\resolvelib\found_candidates.py”, line 143, in
return (c for c in iterator if id© not in self._incompatible_ids)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\gym\AppData\Local\Programs\Python\Python311\Lib\site-packages\pip_internal\resolution\resolvelib\found_candidates.py”, line 47, in _iter_built
candidate = func()
^^^^^^
File “C:\Users\gym\AppData\Local\Programs\Python\Python311\Lib\site-packages\pip_internal\resolution\resolvelib\factory.py”, line 206, in _make_candidate_from_link
self._link_candidate_cache[link] = LinkCandidate(
^^^^^^^^^^^^^^
File “C:\Users\gym\AppData\Local\Programs\Python\Python311\Lib\site-packages\pip_internal\resolution\resolvelib\candidates.py”, line 297, in init
super().init(
File “C:\Users\gym\AppData\Local\Programs\Python\Python311\Lib\site-packages\pip_internal\resolution\resolvelib\candidates.py”, line 162, in init
self.dist = self._prepare()
^^^^^^^^^^^^^^^
File “C:\Users\gym\AppData\Local\Programs\Python\Python311\Lib\site-packages\pip_internal\resolution\resolvelib\candidates.py”, line 231, in _prepare
dist = self._prepare_distribution()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\gym\AppData\Local\Programs\Python\Python311\Lib\site-packages\pip_internal\resolution\resolvelib\candidates.py”, line 308, in _prepare_distribution
return preparer.prepare_linked_requirement(self._ireq, parallel_builds=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\gym\AppData\Local\Programs\Python\Python311\Lib\site-packages\pip_internal\operations\prepare.py”, line 491, in prepare_linked_requirement
return self._prepare_linked_requirement(req, parallel_builds)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\gym\AppData\Local\Programs\Python\Python311\Lib\site-packages\pip_internal\operations\prepare.py”, line 536, in _prepare_linked_requirement
local_file = unpack_url(
^^^^^^^^^^^
File “C:\Users\gym\AppData\Local\Programs\Python\Python311\Lib\site-packages\pip_internal\operations\prepare.py”, line 166, in unpack_url
file = get_http_url(
^^^^^^^^^^^^^
File “C:\Users\gym\AppData\Local\Programs\Python\Python311\Lib\site-packages\pip_internal\operations\prepare.py”, line 107, in get_http_url
from_path, content_type = download(link, temp_dir.path)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\gym\AppData\Local\Programs\Python\Python311\Lib\site-packages\pip_internal\network\download.py”, line 147, in call
for chunk in chunks:
File “C:\Users\gym\AppData\Local\Programs\Python\Python311\Lib\site-packages\pip_internal\cli\progress_bars.py”, line 53, in _rich_progress_bar
for chunk in iterable:
File “C:\Users\gym\AppData\Local\Programs\Python\Python311\Lib\site-packages\pip_internal\network\utils.py”, line 63, in response_chunks
for chunk in response.raw.stream(
File “C:\Users\gym\AppData\Local\Programs\Python\Python311\Lib\site-packages\pip_vendor\urllib3\response.py”, line 621, in stream
data = self.read(amt=amt, decode_content=decode_content)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\gym\AppData\Local\Programs\Python\Python311\Lib\site-packages\pip_vendor\urllib3\response.py”, line 559, in read
with self._error_catcher():
File “C:\Users\gym\AppData\Local\Programs\Python\Python311\Lib\contextlib.py”, line 155, in exit
self.gen.throw(typ, value, traceback)
File “C:\Users\gym\AppData\Local\Programs\Python\Python311\Lib\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

然后查资料, 提示(1)某某问题,没有看明白(2)网络问题。
果断增加了从镜像地址安装:
python -m pip install --user matplotlib -i https://pypi.tuna.tsinghua.edu.cn/simple
执行结果:Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting matplotlib
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/c5/96/40374f9d6f28966ed5ba00c0442ded12cfa2ad17c0c4a4ccd26191d1ecde/matplotlib-3.6.2-cp311-cp311-win_amd64.whl (7.2 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 7.2/7.2 MB 2.9 MB/s eta 0:00:00
Collecting contourpy>=1.0.1
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/56/58/335fb4c504037d9473cb89360cc900e02ad72bb80090cb3128ec16eb9185/contourpy-1.0.6-cp311-cp311-win_amd64.whl (163 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 163.6/163.6 kB 3.3 MB/s eta 0:00:00
Collecting cycler>=0.10
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/5c/f9/695d6bedebd747e5eb0fe8fad57b72fdf25411273a39791cde838d5a8f51/cycler-0.11.0-py3-none-any.whl (6.4 kB)
Collecting fonttools>=4.22.0
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/e3/d9/e9bae85e84737e76ebbcbea13607236da0c0699baed0ae4f1151b728a608/fonttools-4.38.0-py3-none-any.whl (965 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 965.4/965.4 kB 1.4 MB/s eta 0:00:00
Collecting kiwisolver>=1.0.1
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/63/33/a52b723c5e6f1a7b0d73d68761f05ba217519da3ec264ef32dbead9e68ec/kiwisolver-1.4.4-cp311-cp311-win_amd64.whl (55 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 55.4/55.4 kB 2.8 MB/s eta 0:00:00
Collecting numpy>=1.19
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/19/0d/b8c34e4baf258d77a8592bdce45183e9a12874c167f5966c7dd467b74ea9/numpy-1.23.5-cp311-cp311-win_amd64.whl (14.6 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 14.6/14.6 MB 1.2 MB/s eta 0:00:00
Collecting packaging>=20.0
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/8f/7b/42582927d281d7cb035609cd3a543ffac89b74f3f4ee8e1c50914bcb57eb/packaging-22.0-py3-none-any.whl (42 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 42.6/42.6 kB 1.0 MB/s eta 0:00:00
Collecting pillow>=6.2.0
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/d4/0d/e8f6ed8e2328007020bb242a0443d925f23ee06d059486c5f1308f2a5e26/Pillow-9.3.0-cp311-cp311-win_amd64.whl (2.5 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.5/2.5 MB 748.2 kB/s eta 0:00:00
Collecting pyparsing>=2.2.1
Using cached https://pypi.tuna.tsinghua.edu.cn/packages/6c/10/a7d0fa5baea8fe7b50f448ab742f26f52b80bfca85ac2be9d35cdd9a3246/pyparsing-3.0.9-py3-none-any.whl (98 kB)
Collecting python-dateutil>=2.7
Using cached https://pypi.tuna.tsinghua.edu.cn/packages/36/7a/87837f39d0296e723bb9b62bbb257d0355c7f6128853c78955f57342a56d/python_dateutil-2.8.2-py2.py3-none-any.whl (247 kB)
Collecting six>=1.5
Using cached https://pypi.tuna.tsinghua.edu.cn/packages/d9/5a/e7c31adbe875f2abbb91bd84cf2dc52d792b5a01506781dbcf25c91daf11/six-1.16.0-py2.py3-none-any.whl (11 kB)
Installing collected packages: six, pyparsing, pillow, packaging, numpy, kiwisolver, fonttools, cycler, python-dateutil, contourpy, matplotlib
WARNING: The script f2py.exe is installed in ‘C:\Users\gym\AppData\Roaming\Python\Python311\Scripts’ which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
WARNING: The scripts fonttools.exe, pyftmerge.exe, pyftsubset.exe and ttx.exe are installed in ‘C:\Users\gym\AppData\Roaming\Python\Python311\Scripts’ which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed contourpy-1.0.6 cycler-0.11.0 fonttools-4.38.0 kiwisolver-1.4.4 matplotlib-3.6.2 numpy-1.23.5 packaging-22.0 pillow-9.3.0 pyparsing-3.0.9 python-dateutil-2.8.2 six-1.16.0
安装成功。

你可能感兴趣的:(python,matplotlib,vscode,python)