Collecting torch Obtaining dependency information for torch from https://files.pythonhosted.org/packages/13/85/6c1092d4b06c3db1ed23d4106488750917156af0b24ab0a2d9951830b0e9/torch-2.7.0-cp311-cp311-win_amd64.whl.metadata Downloading torch-2.7.0-cp311-cp311-win_amd64.whl.metadata (29 kB) Requirement already satisfied: filelock in d:\sss\python\lib\site-packages (from torch) (3.18.0) Requirement already satisfied: typing-extensions>=4.10.0 in d:\sss\python\lib\site-packages (from torch) (4.13.2) Requirement already satisfied: sympy>=1.13.3 in d:\sss\python\lib\site-packages (from torch) (1.14.0) Requirement already satisfied: networkx in d:\sss\python\lib\site-packages (from torch) (3.4.2) Requirement already satisfied: jinja2 in d:\sss\python\lib\site-packages (from torch) (3.1.6) Requirement already satisfied: fsspec in d:\sss\python\lib\site-packages (from torch) (2025.3.0) Requirement already satisfied: mpmath<1.4,>=1.1.0 in d:\sss\python\lib\site-packages (from sympy>=1.13.3->torch) (1.3.0) Requirement already satisfied: MarkupSafe>=2.0 in d:\sss\python\lib\site-packages (from jinja2->torch) (3.0.2) Downloading torch-2.7.0-cp311-cp311-win_amd64.whl (212.5 MB) 0.2/212.5 MB 8.5 kB/s eta 6:56:59 ERROR: Exception: Traceback (most recent call last): File "D:\sss\python\Lib\site-packages\pip\_vendor\urllib3\response.py", line 438, in _error_catcher yield File "D:\sss\python\Lib\site-packages\pip\_vendor\urllib3\response.py", line 561, in read data = self._fp_read(amt) if not fp_closed else b"" ^^^^^^^^^^^^^^^^^^ File "D:\sss\python\Lib\site-packages\pip\_vendor\urllib3\response.py", line 527, in _fp_read return self._fp.read(amt) if amt is not None else self._fp.read() ^^^^^^^^^^^^^^^^^^ File "D:\sss\python\Lib\site-packages\pip\_vendor\cachecontrol\filewrapper.py", line 90, in read data = self.__fp.read(amt) ^^^^^^^^^^^^^^^^^^^ File "D:\sss\python\Lib\http\client.py", line 473, in read s = self.fp.read(amt) ^^^^^^^^^^^^^^^^^ File "D:\sss\python\Lib\socket.py", line 706, in readinto return self._sock.recv_into(b) ^^^^^^^^^^^^^^^^^^^^^^^ File "D:\sss\python\Lib\ssl.py", line 1315, in recv_into return self.read(nbytes, buffer) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\sss\python\Lib\ssl.py", line 1167, 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 "D:\sss\python\Lib\site-packages\pip\_internal\cli\base_command.py", line 180, in exc_logging_wrapper status = run_func(*args) ^^^^^^^^^^^^^^^ File "D:\sss\python\Lib\site-packages\pip\_internal\cli\req_command.py", line 248, in wrapper return func(self, options, args) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\sss\python\Lib\site-packages\pip\_internal\commands\install.py", line 377, in run requirement_set = resolver.resolve( ^^^^^^^^^^^^^^^^^ File "D:\sss\python\Lib\site-packages\pip\_internal\resolution\resolvelib\resolver.py", line 161, in resolve self.factory.preparer.prepare_linked_requirements_more(reqs) File "D:\sss\python\Lib\site-packages\pip\_internal\operations\prepare.py", line 565, in prepare_linked_requirements_more self._complete_partial_requirements( File "D:\sss\python\Lib\site-packages\pip\_internal\operations\prepare.py", line 479, in _complete_partial_requirements for link, (filepath, _) in batch_download: File "D:\sss\python\Lib\site-packages\pip\_internal\network\download.py", line 183, in __call__ for chunk in chunks: File "D:\sss\python\Lib\site-packages\pip\_internal\cli\progress_bars.py", line 53, in _rich_progress_bar for chunk in iterable: File "D:\sss\python\Lib\site-packages\pip\_internal\network\utils.py", line 63, in response_chunks for chunk in response.raw.stream( File "D:\sss\python\Lib\site-packages\pip\_vendor\urllib3\response.py", line 622, in stream data = self.read(amt=amt, decode_content=decode_content) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\sss\python\Lib\site-packages\pip\_vendor\urllib3\response.py", line 560, in read with self._error_catcher(): File "D:\sss\python\Lib\contextlib.py", line 158, in __exit__ self.gen.throw(typ, value, traceback) File "D:\sss\python\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. [notice] A new release of pip is available: 23.2.1 -> 25.1.1 [notice] To update, run: D:\sss\python\python.exe -m pip install --upgrade pip
时间: 2025-05-31 08:57:01 浏览: 44
### 解决 `pip install torch` 出现 `ReadTimeoutError` 的问题
当执行命令 `pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu113` 时,如果遇到错误提示 `pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='download.pytorch.org', port=443): Read timed out.`[^2],通常是因为网络连接不稳定或者目标服务器响应过慢。
以下是几种解决方案:
#### 方法一:更换国内镜像源
通过指定国内的 Python 镜像站点来加速下载过程。常用的国内镜像有阿里云、清华大学 TUNA 和豆瓣等。例如:
```bash
pip install torch torchvision torchaudio -i https://mirrors.aliyun.com/pypi/simple/
```
或者使用清华大学的镜像源:
```bash
pip install torch torchvision torchaudio -i https://pypi.tuna.tsinghua.edu.cn/simple
```
这种方法能够有效减少因国际网络延迟而导致的超时问题[^5]。
---
#### 方法二:增加超时时间
可以通过设置更大的超时参数 (`--timeout`) 来延长等待时间,从而避免因为短暂的网络波动而引发的超时错误。例如:
```bash
pip install torch torchvision torchaudio --timeout 300 --extra-index-url https://download.pytorch.org/whl/cu113
```
这里将超时时间设为了 300 秒 (即 5 分钟)[^4]。
---
#### 方法三:手动下载并安装 `.whl` 文件
如果仍然无法成功安装,可以选择从官网或其他可信资源处手动下载对应的 `.whl` 文件后再进行本地安装。具体操作如下:
1. 前往 [PyTorch 官方页面](https://pytorch.org/get-started/previous-versions/) 或者其他可靠渠道找到适合当前系统的 `.whl` 文件链接;
2. 使用浏览器直接下载该文件到本地磁盘;
3. 执行以下命令完成安装:
```bash
pip install /path/to/downloaded/file.whl
```
这种方式适用于那些由于特殊原因始终无法在线正常工作的场景[^4]。
---
#### 方法四:升级或降级 PyTorch 版本
有时特定版本可能存在问题,尝试切换至稳定版可能会有所帮助。比如按照引用中的例子指定较低版本号来进行安装:
```bash
pip install torch==1.5.0+cu101 torchvision==0.6.0+cu101 -f https://download.pytorch.org/whl/torch_stable.html
```
此方法特别针对某些硬件配置下兼容性不佳的情况作出调整[^3]。
---
### 注意事项
无论采用哪种策略解决问题,在实际应用之前都应该确认所依赖库的具体需求以及自身计算平台的相关特性(如 CUDA 版本),以免引入新的冲突或异常状况。
---
阅读全文
相关推荐



















