安装Pygame过程中提示错误WARNING: Retrying…ERROR: Exception: Traceback…WARNING: You are using pip version解决方案
前言
输入Pygame安装命令
pip install pygame
安装Pygame出错提示错误:WARNING: Retrying…ERROR: Exception: Traceback…WARNING: You are using pip version,怎么解决?
Pygame错误
安装Pygame提示错误如下:
C:\Users\LVWIN>pip install pygame
Collecting pygame
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPSConnection object at 0x00000161F90F83D0>, 'Connection to files.pythonhosted.org timed out. (connect timeout=15)')': /packages/7f/d9/098baed5e89684f95d042d7d22fc8c0d684748601357cfc884df02bbc43a/pygame-2.5.2-cp39-cp39-win_amd64.whl
Downloading pygame-2.5.2-cp39-cp39-win_amd64.whl (10.8 MB)
-- ------------------------------------- 0.6/10.8 MB 6.5 kB/s eta 0:25:51
ERROR: Exception:
Traceback (most recent call last):
File "C:\Python39\lib\site-packages\pip\_vendor\urllib3\response.py", line 438, in _error_catcher
yield
File "C:\Python39\lib\site-packages\pip\_vendor\urllib3\response.py", line 519, in read
data = self._fp.read(amt) if not fp_closed else b""
File "C:\Python39\lib\site-packages\pip\_vendor\cachecontrol\filewrapper.py", line 90, in read
data = self.__fp.read(amt)
File "C:\Python39\lib\http\client.py", line 463, in read
n = self.readinto(b)
File "C:\Python39\lib\http\client.py", line 507, in readinto
n = self.fp.readinto(b)
File "C:\Python39\lib\socket.py", line 704, in readinto
return self._sock.recv_into(b)
File "C:\Python39\lib\ssl.py", line 1242, in recv_into
return self.read(nbytes, buffer)
File "C:\Python39\lib\ssl.py", line 1100, 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:\Python39\lib\site-packages\pip\_internal\cli\base_command.py", line 167, in exc_logging_wrapper
status = run_func(*args)
File "C:\Python39\lib\site-packages\pip\_internal\cli\req_command.py", line 205, in wrapper
return func(self, options, args)
File "C:\Python39\lib\site-packages\pip\_internal\commands\install.py", line 339, in run
requirement_set = resolver.resolve(
File "C:\Python39\lib\site-packages\pip\_internal\resolution\resolvelib\resolver.py", line 94, in resolve
result = self._result = resolver.resolve(
File "C:\Python39\lib\site-packages\pip\_vendor\resolvelib\resolvers.py", line 481, in resolve
state = resolution.resolve(requirements, max_rounds=max_rounds)
File "C:\Python39\lib\site-packages\pip\_vendor\resolvelib\resolvers.py", line 348, in resolve
self._add_to_criteria(self.state.criteria, r, parent=None)
File "C:\Python39\lib\site-packages\pip\_vendor\resolvelib\resolvers.py", line 172, in _add_to_criteria
if not criterion.candidates:
File "C:\Python39\lib\site-packages\pip\_vendor\resolvelib\structs.py", line 151, in __bool__
return bool(self._sequence)
File "C:\Python39\lib\site-packages\pip\_internal\resolution\resolvelib\found_candidates.py", line 155, in __bool__
return any(self)
File "C:\Python39\lib\site-packages\pip\_internal\resolution\resolvelib\found_candidates.py", line 143, in <genexpr>
return (c for c in iterator if id(c) not in self._incompatible_ids)
File "C:\Python39\lib\site-packages\pip\_internal\resolution\resolvelib\found_candidates.py", line 47, in _iter_built
candidate = func()
File "C:\Python39\lib\site-packages\pip\_internal\resolution\resolvelib\factory.py", line 215, in _make_candidate_from_link
self._link_candidate_cache[link] = LinkCandidate(
File "C:\Python39\lib\site-packages\pip\_internal\resolution\resolvelib\candidates.py", line 288, in __init__
super().__init__(
File "C:\Python39\lib\site-packages\pip\_internal\resolution\resolvelib\candidates.py", line 158, in __init__
self.dist = self._prepare()
File "C:\Python39\lib\site-packages\pip\_internal\resolution\resolvelib\candidates.py", line 227, in _prepare
dist = self._prepare_distribution()
File "C:\Python39\lib\site-packages\pip\_internal\resolution\resolvelib\candidates.py", line 299, in _prepare_distribution
return preparer.prepare_linked_requirement(self._ireq, parallel_builds=True)
File "C:\Python39\lib\site-packages\pip\_internal\operations\prepare.py", line 487, in prepare_linked_requirement
return self._prepare_linked_requirement(req, parallel_builds)
File "C:\Python39\lib\site-packages\pip\_internal\operations\prepare.py", line 532, in _prepare_linked_requirement
local_file = unpack_url(
File "C:\Python39\lib\site-packages\pip\_internal\operations\prepare.py", line 214, in unpack_url
file = get_http_url(
File "C:\Python39\lib\site-packages\pip\_internal\operations\prepare.py", line 94, in get_http_url
from_path, content_type = download(link, temp_dir.path)
File "C:\Python39\lib\site-packages\pip\_internal\network\download.py", line 146, in __call__
for chunk in chunks:
File "C:\Python39\lib\site-packages\pip\_internal\cli\progress_bars.py", line 304, in _rich_progress_bar
for chunk in iterable:
File "C:\Python39\lib\site-packages\pip\_internal\network\utils.py", line 63, in response_chunks
for chunk in response.raw.stream(
File "C:\Python39\lib\site-packages\pip\_vendor\urllib3\response.py", line 576, in stream
data = self.read(amt=amt, decode_content=decode_content)
File "C:\Python39\lib\site-packages\pip\_vendor\urllib3\response.py", line 541, in read
raise IncompleteRead(self._fp_bytes_read, self.length_remaining)
File "C:\Python39\lib\contextlib.py", line 137, in __exit__
self.gen.throw(typ, value, traceback)
File "C:\Python39\lib\site-packages\pip\_vendor\urllib3\response.py", line 443, 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.
WARNING: You are using pip version 22.0.4; however, version 24.0 is available.
You should consider upgrading via the 'C:\Python39\python.exe -m pip install --upgrade pip' command.
错误分析
显示的错误是在连接Pygame的时候发生多次错误警告,连接异常警告,导致下载Pygame的数据出错。
追溯数据出错在于pip(Python的包管理器)的版本太旧导致无法正常下载Pygame导致Pygame安装失败。
解决方案
错误分析结论
通过错误分析得到的结论,我们需要更新pip(Python的包管理器)为最新版本就可以解决这个错误
更新pip
- 我们用win+R打开运行窗口
- 在运行窗口输入更新pip(Python的包管理器)的命令如下:
[python程序地址] -m pip install --upgrade pip
老吕的[python程序地址]是C:\Python39\python.exe,所以命令修改如下示例:
C:\Python39\python.exe -m pip install --upgrade pip
特别提醒:必须是.exe完整输入,有些朋友直接写
python -m pip install --upgrade pip
注意exe和后面的-m pip install
和--upgrade pip
命令之间都是有空格的,不能省略哦。
比如你的python安装在d盘的python文件夹,路径为d:\python,我们的命令则修改为:
d:\python\python.exe -m pip install --upgrade pip
- 再次输入确定更新pip(Python的包管理器)是否成功
以上证明我们的pip(Python的包管理器)已经成功更新到最新版24.0了
安装Pygame
接下来,我们尝试重新安装Pygame是否能成功
输入Pygame安装命令
pip install pygame
OK,按照页面提示,我们已经成功安装了Pygame 2.5.2版本。
👨💻博主Python老吕说:如果您觉得本文有帮助,辛苦您🙏帮忙点赞、收藏、评论,您的举手之劳将对我提供了无限的写作动力!🤞
print('Hello,World!') # 每日一码,用Python跟世界说Hello,World!
🔥精品付费专栏:《Python全栈工程师》、《跟老吕学MySQL》、《Python游戏开发实战讲解》
🌞精品免费专栏:《Python全栈工程师·附录资料》、《Pillow库·附录资料》、《Pygame·附录资料》、《Tkinter·附录资料》、《Django·附录资料》、《NumPy·附录资料》、《Pandas·附录资料》、《Matplotlib·附录资料》、《Python爬虫·附录资料》
🌐前端免费专栏:《HTML》、《CSS》、《JavaScript》、《Vue》
💻后端免费专栏:《C语言》、《C++语言》、《Java语言》、《R语言》、《Ruby语言》、《PHP语言》、《Go语言》、《C#语言》、《Swift语言》、《跟老吕学Python编程·附录资料》
💾数据库免费专栏:《Oracle》、《MYSQL》、《SQL》、《PostgreSQL》、《MongoDB》