Skip to content

Instantly share code, notes, and snippets.

@woq
Created June 30, 2025 02:40
Show Gist options
  • Save woq/8d61eb23fee05c54444ae59642de918e to your computer and use it in GitHub Desktop.
Save woq/8d61eb23fee05c54444ae59642de918e to your computer and use it in GitHub Desktop.
uv mirror cn windows config
import os
import sys
from pathlib import Path
def main():
# 获取系统驱动器
system_drive = os.environ.get('SYSTEMDRIVE', 'C:')
# 配置文件路径
config_dir = Path(f"{system_drive}\\ProgramData\\uv")
config_file = config_dir / "uv.toml"
# 确保目录存在
try:
config_dir.mkdir(parents=True, exist_ok=True)
except PermissionError:
print("错误:没有权限创建目录。请以管理员身份运行此脚本。")
sys.exit(1)
# 配置内容
config_content = """[[index]]
# 华为云镜像 (优先使用)
name = "huaweicloud"
url = "https://repo.huaweicloud.com/repository/pypi/simple"
default = true
[[index]]
# 阿里云镜像
name = "aliyun"
url = "https://mirrors.aliyun.com/pypi/simple/"
[[index]]
# 腾讯云镜像
name = "tencent"
url = "https://mirrors.cloud.tencent.com/pypi/simple"
[[index]]
# 清华大学镜像
name = "tsinghua"
url = "https://pypi.tuna.tsinghua.edu.cn/simple"
[[index]]
# 北京大学镜像
name = "pku"
url = "https://mirrors.pku.edu.cn/pypi/web/simple"
"""
# 写入配置文件
try:
with open(config_file, 'w', encoding='utf-8') as f:
f.write(config_content)
print(f"配置文件已成功创建:{config_file}")
except PermissionError:
print("错误:没有权限写入文件。请以管理员身份运行此脚本。")
sys.exit(1)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment