当前位置: 首页 > news >正文

Python因为网络原因安装依赖库报错

现象

在终端运行以下指令

pip install pyautogui pillow keyboard

出现报错,终端信息如下:

PS D:\code\Python> pip install pyautogui pillow keyboard
Collecting pyautoguiUsing cached PyAutoGUI-0.9.54.tar.gz (61 kB)Installing build dependencies ... doneGetting requirements to build wheel ... donePreparing metadata (pyproject.toml) ... done
Collecting pillowUsing cached pillow-11.1.0-cp39-cp39-win_amd64.whl.metadata (9.3 kB)
Collecting keyboardUsing cached keyboard-0.13.5-py3-none-any.whl.metadata (4.0 kB)
Collecting pymsgbox (from pyautogui)Using cached PyMsgBox-1.0.9.tar.gz (18 kB)Installing build dependencies ... doneGetting requirements to build wheel ... donePreparing metadata (pyproject.toml) ... done
Collecting pytweening>=1.0.4 (from pyautogui)Using cached pytweening-1.2.0.tar.gz (171 kB)Installing build dependencies ... doneGetting requirements to build wheel ... donePreparing metadata (pyproject.toml) ... done
Collecting pyscreeze>=0.1.21 (from pyautogui)Using cached pyscreeze-1.0.1.tar.gz (27 kB)Installing build dependencies ... doneGetting requirements to build wheel ... donePreparing metadata (pyproject.toml) ... done
Collecting pygetwindow>=0.0.5 (from pyautogui)Downloading PyGetWindow-0.0.9.tar.gz (9.7 kB)[notice] A new release of pip is available: 24.3.1 -> 25.0
[notice] To update, run: python.exe -m pip install --upgrade pip
ERROR: Exception:
Traceback (most recent call last):File "C:\Users\zando\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_vendor\urllib3\response.py", line 438, in _error_catcheryieldFile "C:\Users\zando\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_vendor\urllib3\response.py", line 561, in readdata = self._fp_read(amt) if not fp_closed else b""File "C:\Users\zando\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_vendor\urllib3\response.py", line 527, in _fp_readreturn self._fp.read(amt) if amt is not None else self._fp.read()File "C:\Users\zando\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_vendor\cachecontrol\filewrapper.py", line 98, in readdata: bytes = self.__fp.read(amt)File "C:\Users\zando\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 463, in readn = self.readinto(b)File "C:\Users\zando\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 507, in readinton = self.fp.readinto(b)File "C:\Users\zando\AppData\Local\Programs\Python\Python39\lib\socket.py", line 704, in readintoreturn self._sock.recv_into(b)File "C:\Users\zando\AppData\Local\Programs\Python\Python39\lib\ssl.py", line 1241, in recv_intoreturn self.read(nbytes, buffer)File "C:\Users\zando\AppData\Local\Programs\Python\Python39\lib\ssl.py", line 1099, in readreturn self._sslobj.read(len, buffer)
socket.timeout: The read operation timed outDuring handling of the above exception, another exception occurred:Traceback (most recent call last):File "C:\Users\zando\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_internal\cli\base_command.py", line 105, in _run_wrapperstatus = _inner_run()File "C:\Users\zando\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_internal\cli\base_command.py", line 96, in _inner_runreturn self.run(options, args)File "C:\Users\zando\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_internal\cli\req_command.py", line 67, in wrapperreturn func(self, options, args)File "C:\Users\zando\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_internal\commands\install.py", line 379, in runrequirement_set = resolver.resolve(File "C:\Users\zando\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_internal\resolution\resolvelib\resolver.py", line 95, in resolveresult = self._result = resolver.resolve(File "C:\Users\zando\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_vendor\resolvelib\resolvers.py", line 546, in resolvestate = resolution.resolve(requirements, max_rounds=max_rounds)File "C:\Users\zando\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_vendor\resolvelib\resolvers.py", line 427, in resolvefailure_causes = self._attempt_to_pin_criterion(name)File "C:\Users\zando\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_vendor\resolvelib\resolvers.py", line 239, in _attempt_to_pin_criterioncriteria = self._get_updated_criteria(candidate)File "C:\Users\zando\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_vendor\resolvelib\resolvers.py", line 230, in _get_updated_criteriaself._add_to_criteria(criteria, requirement, parent=candidate)File "C:\Users\zando\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_vendor\resolvelib\resolvers.py", line 173, in _add_to_criteriaif not criterion.candidates:File "C:\Users\zando\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_vendor\resolvelib\structs.py", line 156, in __bool__return bool(self._sequence)File "C:\Users\zando\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_internal\resolution\resolvelib\found_candidates.py", line 174, in __bool__return any(self)File "C:\Users\zando\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_internal\resolution\resolvelib\found_candidates.py", line 162, in <genexpr>return (c for c in iterator if id(c) not in self._incompatible_ids)File "C:\Users\zando\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_internal\resolution\resolvelib\found_candidates.py", line 53, in _iter_built        candidate = func()File "C:\Users\zando\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_internal\resolution\resolvelib\factory.py", line 187, in _make_candidate_from_link  base: Optional[BaseCandidate] = self._make_base_candidate_from_link(File "C:\Users\zando\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_internal\resolution\resolvelib\factory.py", line 233, in _make_base_candidate_from_linkself._link_candidate_cache[link] = LinkCandidate(File "C:\Users\zando\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_internal\resolution\resolvelib\candidates.py", line 304, in __init__super().__init__(File "C:\Users\zando\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_internal\resolution\resolvelib\candidates.py", line 159, in __init__self.dist = self._prepare()File "C:\Users\zando\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_internal\resolution\resolvelib\candidates.py", line 236, in _preparedist = self._prepare_distribution()File "C:\Users\zando\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_internal\resolution\resolvelib\candidates.py", line 315, in _prepare_distribution   return preparer.prepare_linked_requirement(self._ireq, parallel_builds=True)File "C:\Users\zando\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_internal\operations\prepare.py", line 527, in prepare_linked_requirementreturn self._prepare_linked_requirement(req, parallel_builds)File "C:\Users\zando\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_internal\operations\prepare.py", line 598, in _prepare_linked_requirementlocal_file = unpack_url(File "C:\Users\zando\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_internal\operations\prepare.py", line 170, in unpack_urlfile = get_http_url(File "C:\Users\zando\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_internal\operations\prepare.py", line 111, in get_http_urlfrom_path, content_type = download(link, temp_dir.path)File "C:\Users\zando\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_internal\network\download.py", line 148, in __call__for chunk in chunks:File "C:\Users\zando\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_internal\network\utils.py", line 65, in response_chunksfor chunk in response.raw.stream(File "C:\Users\zando\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_vendor\urllib3\response.py", line 622, in streamdata = self.read(amt=amt, decode_content=decode_content)File "C:\Users\zando\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_vendor\urllib3\response.py", line 587, in readraise IncompleteRead(self._fp_bytes_read, self.length_remaining)File "C:\Users\zando\AppData\Local\Programs\Python\Python39\lib\contextlib.py", line 137, in __exit__self.gen.throw(typ, value, traceback)File "C:\Users\zando\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_vendor\urllib3\response.py", line 443, in _error_catcherraise ReadTimeoutError(self._pool, None, "Read timed out.")
pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.

原因

默认的pypi.org服务器在国外,国内访问可能较慢

改为执行如下命令,使用国内镜像源加速下载:

pip install pyautogui pillow keyboard -i https://pypi.tuna.tsinghua.edu.cn/simple

改镜像源为清华镜像源,还有常用镜像源如下:

阿里云:

https://mirrors.aliyun.com/pypi/simple

豆瓣:

https://pypi.douban.com/simple

换源之后成功安装依赖库,终端信息如下:

PS D:\code\Python> pip install pyautogui pillow keyboard -i https://pypi.tuna.tsinghua.edu.cn/simple
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Requirement already satisfied: pyautogui in c:\users\zando\appdata\local\programs\python\python39\lib\site-packages (0.9.54)
Requirement already satisfied: pillow in c:\users\zando\appdata\local\programs\python\python39\lib\site-packages (11.1.0)
Collecting keyboardDownloading https://pypi.tuna.tsinghua.edu.cn/packages/55/88/287159903c5b3fc6d47b651c7ab65a54dcf9c9916de546188a7f62870d6d/keyboard-0.13.5-py3-none-any.whl (58 kB)
Requirement already satisfied: pymsgbox in c:\users\zando\appdata\local\programs\python\python39\lib\site-packages (from pyautogui) (1.0.9)
Requirement already satisfied: pytweening>=1.0.4 in c:\users\zando\appdata\local\programs\python\python39\lib\site-packages (from pyautogui) (1.2.0)
Requirement already satisfied: pyscreeze>=0.1.21 in c:\users\zando\appdata\local\programs\python\python39\lib\site-packages (from pyautogui) (1.0.1)
Requirement already satisfied: pygetwindow>=0.0.5 in c:\users\zando\appdata\local\programs\python\python39\lib\site-packages (from pyautogui) (0.0.9)
Requirement already satisfied: mouseinfo in c:\users\zando\appdata\local\programs\python\python39\lib\site-packages (from pyautogui) (0.1.3)
Requirement already satisfied: pyrect in c:\users\zando\appdata\local\programs\python\python39\lib\site-packages (from pygetwindow>=0.0.5->pyautogui) (0.2.0)
Requirement already satisfied: pyperclip in c:\users\zando\appdata\local\programs\python\python39\lib\site-packages (from mouseinfo->pyautogui) (1.9.0)
Installing collected packages: keyboard
Successfully installed keyboard-0.13.5[notice] A new release of pip is available: 24.3.1 -> 25.0
[notice] To update, run: python.exe -m pip install --upgrade pip

http://www.lryc.cn/news/532409.html

相关文章:

  • 什么是卸荷器?风力发电为什么要用卸荷器
  • SQL Server详细使用教程(包含启动SQL server服务、建立数据库、建表的详细操作) 非常适合初学者
  • 大数据学习之Spark分布式计算框架RDD、内核进阶
  • Unity 加载OSGB(webgl直接加载,无需转换格式!)
  • tcp/ip网络协议,tcp/ip网络协议栈
  • 【Debug】the remote host closed the connection错误信息分析
  • SpringBoot扩展篇:@Scope和@Lazy源码解析
  • “AI隐患识别系统,安全多了道“智能护盾”
  • 通向AGI之路:人工通用智能的技术演进与人类未来
  • 论文阅读:InstanceDiffusion: Instance-level Control for Image Generation
  • 7.攻防世界 wzsc_文件上传
  • 以为是响应式对象丢失导致数据没有回显
  • 来 Gitcode 免费体验 DeepSeek 蒸馏模型,开启 AI 探索新旅程
  • 2.Mkdocs配置说明(mkdocs.yml)【最新版】
  • 云轴科技ZStack+海光DCU:率先推出DeepSeek私有化部署方案
  • 扩增子分析|零模型2——基于βNTI的微生物随机性和确定性装配过程(箱线图和柱状图R中实现)
  • 专题:剑指offer
  • DeepSeek 部署过程中的问题
  • DeepSeek R1本地化部署 Ollama + Chatbox 打造最强 AI 工具
  • 应急场景中的数据融合与对齐
  • 手机上运行AI大模型(Deepseek等)
  • Mellanox网卡信息查看
  • 【漫画机器学习】083.安斯库姆四重奏(Anscombe‘s quartet)
  • TCP | RFC793
  • 2025蓝桥杯JAVA编程题练习Day2
  • 《解锁GANs黑科技:打造影视游戏的逼真3D模型》
  • es match 可查 而 term 查不到 问题分析
  • 【OpenCV实战】基于 OpenCV 的多尺度与模板匹配目标跟踪设计与实现
  • 将有序数组转换为二叉搜索树(力扣108)
  • 开放式TCP/IP通信