ERROR: Exception: Traceback (most recent call last): File "F:\anaconda\Lib\site-packages\pip\_vendor\urllib3\response.py", line 438, in _error_catcher yield File "F:\anaconda\Lib\site-packages\pip\_vendor\urllib3\response.py", line 561, in read data = self._fp_read(amt) if not fp_closed else b"" ^^^^^^^^^^^^^^^^^^ File "F:\anaconda\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 "F:\anaconda\Lib\site-packages\pip\_vendor\cachecontrol\filewrapper.py", line 98, in read data: bytes = self.__fp.read(amt) ^^^^^^^^^^^^^^^^^^^ File "F:\anaconda\Lib\http\client.py", line 479, in read s = self.fp.read(amt) ^^^^^^^^^^^^^^^^^ File "F:\anaconda\Lib\socket.py", line 707, in readinto return self._sock.recv_into(b) ^^^^^^^^^^^^^^^^^^^^^^^ File "F:\anaconda\Lib\ssl.py", line 1252, in recv_into return self.read(nbytes, buffer) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "F:\anaconda\Lib\ssl.py", line 1104, 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 "F:\anaconda\Lib\site-packages\pip\_internal\cli\base_command.py", line 180, in exc_logging_wrapper status = run_func(*args) ^^^^^^^^^^^^^^^ File "F:\anaconda\Lib\site-packages\pip\_internal\cli\req_command.py", line 245, in wrapper return func(self, options, args) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "F:\anaconda\Lib\site-packages\pip\_internal\commands\install.py", line 377, in run requirement_set = resolver.resolve( ^^^^^^^^^^^^^^^^^ File "F:\anaconda\Lib\site-packages\pip\_internal\resolution\resolvelib\resolver.py", line 179, in resolve self.factory.preparer.prepare_linked_requirements_more(reqs) File "F:\anaconda\Lib\site-packages\pip\_internal\operations\prepare.py", line 552, in prepare_linked_requirements_more self._complete_partial_requirements( File "F:\anaconda\Lib\site-packages\pip\_internal\operations\prepare.py", line 467, in _complete_partial_requirements for link, (filepath, _) in batch_download: File "F:\anaconda\Lib\site-packages\pip\_internal\network\download.py", line 183, in __call__ for chunk in chunks: File "F:\anaconda\Lib\site-packages\pip\_internal\cli\progress_bars.py", line 53, in _rich_progress_bar for chunk in iterable: File "F:\anaconda\Lib\site-packages\pip\_internal\network\utils.py", line 63, in response_chunks for chunk in response.raw.stream( File "F:\anaconda\Lib\site-packages\pip\_vendor\urllib3\response.py", line 622, in stream data = self.read(amt=amt, decode_content=decode_content) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "F:\anaconda\Lib\site-packages\pip\_vendor\urllib3\response.py", line 560, in read with self._error_catcher(): File "F:\anaconda\Lib\contextlib.py", line 158, in __exit__ self.gen.throw(value) File "F:\anaconda\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.
时间: 2025-05-30 20:12:08 浏览: 52
### 解决 `pip install ray` 出现 `ReadTimeoutError` 的方法
当执行 `pip install ray` 时遇到 `ReadTimeoutError` 错误,通常是因为网络连接不稳定或无法及时从默认的 PyPI 仓库下载所需的文件。以下是几种有效的解决方案:
#### 1. **更换为国内镜像源**
由于国外服务器可能受到网络延迟的影响,建议切换到国内的 PyPI 镜像站点以提高下载速度和稳定性[^1]。
```bash
pip install ray -i https://pypi.tuna.tsinghua.edu.cn/simple
```
常用的国内镜像源包括但不限于:
- 清华大学 TUNA 镜像站: `https://pypi.tuna.tsinghua.edu.cn/simple`
- 阿里云镜像站: `https://mirrors.aliyun.com/pypi/simple/`
- 华东理工大学 NEXUS 镜像站: `http://mirror.neu.edu.cn/pypi/web/simple/`
#### 2. **增加超时时间**
可以通过设置更大的超时参数来延长等待时间,从而减少因短暂网络波动引发的读取超时问题。
```bash
pip install --timeout=60 ray
```
此处将超时时间设为了 60 秒,默认值一般较小,因此适当增大可以有效缓解该类错误的发生概率。
#### 3. **分步安装依赖**
有时一次性安装整个项目及其所有依赖容易触发网络异常,尝试先单独安装一些主要依赖再继续完成其余部分。
```bash
pip install numpy scipy pandas -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install ray -i https://pypi.tuna.tsinghua.edu.cn/simple
```
这样能够更精确地定位到底是哪个具体的子包造成了麻烦,并针对性处理。
#### 4. **离线模式安装**
如果持续遭遇网络障碍,考虑采用离线方式获取所需 whl 文件后再手动加载入本地环境。
前往 [PyPI](https://pypi.org/project/ray/#files) 下载对应平台架构版本的 wheel 包后上传至目标机器:
```bash
pip install ./downloads/ray-X.X.X-py3-none-any.whl
```
注意替换实际路径与文件名即可。
---
### 提供一段简单的测试脚本验证安装成功与否
下面给出了一段用来检测 Ray 是否正常工作的 Python 测试代码:
```python
import ray
@ray.remote
def f(x):
return x * x
if __name__ == "__main__":
ray.init()
futures = [f.remote(i) for i in range(4)]
print(ray.get(futures))
```
运行以上程序应返回 `[0, 1, 4, 9]` 结果表示一切运作良好。
阅读全文
相关推荐



















