问题描述
在使用 uv 工具安装 Python 3.11 时报以下错误:
error: Failed to install cpython-3.11.13-windows-x86_64-none Caused by: Failed to download https://github.com/astral-sh/python-build-standalone/releases/download/20250808/cpython-3.11.13%2B20250808-x86_64-pc-windows-msvc-install_only_stripped.tar.gz
Caused by: Request failed after 3 retries Caused by: error sending request for url (https://github.com/astral-sh/python-build-standalone/releases/download/20250808/cpython-3.11.13%2B20250808-x86_64-pc-windows-msvc-install_only_stripped.tar.gz) Caused by: client error (Connect) Caused by: tcp connect error Caused by: 由于目标计算机积极拒绝,无法连接。 (os error 10061)
该错误通常由网络连接超时或无法访问 GitHub Releases 资源导致。
解决方法
1. 设置环境变量
通过设置环境变量指定 Python 安装目录、缓存目录及镜像源地址。示例如下(Windows CMD):
set UV_PYTHON_INSTALL_DIR=E:\uv\python
set UV_CACHE_DIR=E:\uv\cache
set UV_TOOL_DIR=E:\uv\tools
set UV_PYTHON_INSTALL_MIRROR=https://gh-proxy.com/github.com/astral-sh/python-build-standalone/releases/download/
2. 配置 uv 镜像源
打开命令行,输入以下命令新建配置目录并创建配置文件:
md %UserProfile%\.config\uv
notepad %UserProfile%\.config\uv\uv.toml
在 uv.toml 文件中添加以下内容以配置 PyPI 镜像:
[[index]]
url = "https://pypi.tuna.tsinghua.edu.cn/simple"
default = true
3. 以管理员身份运行 Shell
确保使用管理员权限打开命令行窗口,以避免权限不足导致的写入失败。
4. 执行安装命令
在管理员 Shell 中重新执行安装命令:
uv python install 3.11
完成上述步骤后,Python 3.11 即可成功安装。


