Skip to content

Windows 下 uv 换源方法错误 #196

Closed
Closed

Description

@xrgzs

你操作了什么?

chsrc set uv

发生了什么?

换源没有生效,写 uv.toml 配置文件的位置错误。

本应该怎么样?

根据 文档:

uv will also discover user-level configuration at ~/.config/uv/uv.toml (or $XDG_CONFIG_HOME/uv/uv.toml) on macOS and Linux, or %APPDATA%\uv\uv.toml on Windows; and system-level configuration at /etc/uv/uv.toml (or $XDG_CONFIG_DIRS/uv/uv.toml) on macOS and Linux, or %SYSTEMDRIVE%\ProgramData\uv\uv.toml on Windows.

Windows 的路径应该为 %APPDATA%\uv\uv.toml,如:C:\Users\Xiaoran\AppData\Roaming\uv\uv.toml。

存放到 ~/.config/uv/uv.toml 则不会读取,换源失败。

chsrc 版本

chsrc: Change Source (GPLv3+) v0.2.1-2025/04/13 by RubyMetric

你使用的是哪个操作系统?

Windows

OS 版本 / OS 发行版

Microsoft Windows [版本 10.0.19045.5608]

Log 输出

PS> chsrc set uv
[chsrc 测速] 测速中

  ^ 上游默认源 (https://pypi.org/simple) ... 0.00 Byte/s | HTTP码 000
  - 北京外国语大学开源软件镜像站 ... 52.22 MByte/s
  - 兰州大学开源社区镜像站 ... 34.67 MByte/s
  - 吉林大学开源镜像站 ... 41.20 MByte/s
  - 上海交通大学致远镜像站 ... 39.38 MByte/s
  - 清华大学开源软件镜像站 ... 42.01 MByte/s
  - 阿里巴巴开源镜像站(公网) ... 491.14 KByte/s
  - 南京大学开源镜像站 ... 20.32 MByte/s
  - 北京大学开源镜像站 ... 39.73 MByte/s
  - 腾讯软件源(公网) ... 99.86 KByte/s
  - 华为开源镜像站 ... 56.51 MByte/s
  - 华中科技大学开源镜像站 ... 39.05 MByte/s

最快镜像站: 华为开源镜像站
[chsrc 提示] 目录不存在,已自动创建 C:\Users\Xiaoran\.config\uv\
[chsrc 提示] 文件不存在,跳过备份: ~/.config/uv/uv.toml
[chsrc 运行] printf '[[index]]
url = "https://mirrors.huaweicloud.com/repository/pypi/simple"
default = true
' >> ~/.config/uv/uv.toml
'[[index]][chsrc 运行] ✓ 命令执行成功

--------------------------------
chsrc: 全自动换源完成, 感谢镜像提供方: 华为开源镜像站
PS> uv add requests
⠸ charset-normalizer==3.4.2 ...等半天都没反应

防止重复问题

  • 我已在项目的 GitHub 和 Gitee 两个仓库分别搜索过类似的 issue

Activity

  1. added this to the v0.2.2 milestone on May 15, 2025
  2. added theissue type on May 15, 2025
  3. changed the issue type fromtoon May 15, 2025
  4. added and removed on May 15, 2025
  5. self-assigned this
    on May 20, 2025
  6. happy-game commented on Jun 1, 2025

    @happy-game
    Collaborator

    事实上不只是存在这一问题, 因为有些命令无法使用(printf, grep, sed), 在 windows 上为 uv换源的命令也无法很好地运行.

    这个问题应该要花费较长的时间去解决.

  7. xrgzs commented on Jun 2, 2025

    @xrgzs
    ContributorAuthor

    有些命令无法使用(printf, grep, sed)

    我的Windows环境中已安装busybox,printf命令运行正常。此issue的核心问题在于文件路径错误。不过,若能避免依赖第三方组件,直接采用 C 原生方法实现文件读写和内容替换功能会是更优的解决方案。

  8. happy-game commented on Jun 2, 2025

    @happy-game
    Collaborator

    我的Windows环境中已安装busybox,printf命令运行正常。此issue的核心问题在于文件路径错误。不过,若能避免依赖第三方组件,直接采用 C 原生方法实现文件读写和内容替换功能会是更优的解决方案。

    感谢提醒, 已在 #200 中实现, 等合并后可以拉取最新的 dev 分支进行测试.

  9. happy-game commented on Jun 2, 2025

    @happy-game
    Collaborator

    但目前仍存在一些问题, 由于 grep, sed命令的行为在 windows 的 Cygwin环境下存在差异(busybox中没有测试), 故暂时不支持直接修改已存在的 uv.toml, 需等待后续解决.

  10. ccmywish commented on Jul 26, 2025

    @ccmywish
    Contributor

    @xrgzs

    再试试最新版 v0.2.2,不再依赖 printf,只依赖 grep 和 sed,如果没啥问题,这个 issue 可以关闭了。

    关于 Windows 上的 grep 和 sed 等其他工具依赖,可以在 discussion #201 接着讨论

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions