前置知识点

pixi是什么

pixi是一个新兴的跨平台包管理工具, 尤其适合python使用。它建立在conda之上, 因此添加包时(即命令pixi add <packageName>)默认通过conda渠道下载; 不过其也支持从pypi渠道(即常用的pip命令)下载python包, 只需在命令后额外添加–pypi的参数即可(即pixi add <packageName> --pypi)。

为什么要为pixi配置镜像源

对于conda渠道, 国内通常访问流畅, 因此可选择性配置其镜像源; 但对于pypi渠道, 国内通常需要配置镜像源后才可流畅下载, 因此后续介绍的配置中, 您几乎是必须配置它的。 总之, 我会将两者的配置给出, 您可以选择仅配置pypi的镜像源或两者都配置。

此外pixi官网上, 还介绍了一个OCI镜像, 感兴趣的小伙伴也可以对齐进行配置, 本文不对此过多介绍。

镜像源的配置可精确到哪些范围?

以windows为例介绍, 优先级由高到低排序:

  • 命令行参数( --tls-no-verify--change-ps1=false 等), 通过命令行参数配置
  • your_project\.pixi\config.toml, 项目特定配置。
  • %PIXI_HOME%\config.toml, PIXI_HOME中的全局配置。
  • %USERPROFILE%\.pixi\config.toml, 用户主目录中的全局配置。
  • %APPDATA%\pixi\config.toml, 用户特定配置。
  • C:\ProgramData\pixi\config.toml, 系统范围的配置。

具体各个平台的配置优先级列表, 可点击此处从官方文档查看。

pixi镜像源的具体配置

config.toml

根据自己的所需范围创建对应的config.toml

设置config.toml后,新建项目才会将pypi镜像加入到项目内的pyproject.toml或pixi.toml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# [concurrency]
# downloads = 12

[pypi-config]
extra-index-urls = [
"https://pypi.tuna.tsinghua.edu.cn/simple",
"https://pypi.org/simple",
]
index-url = "https://mirrors.aliyun.com/pypi/simple"
# can be "subprocess" or "disabled"
# keyring-provider = "subprocess"

[mirrors]
"https://conda.anaconda.org/bioconda" = [
"https://mirrors.ustc.edu.cn/anaconda/cloud/bioconda",
]
"https://conda.anaconda.org/conda-forge" = [
"https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge",
]
"https://conda.anaconda.org/pytorch" = [
"https://mirrors.ustc.edu.cn/anaconda/cloud/pytorch",
]
"https://repo.anaconda.com/pkgs/main" = [
"https://mirrors.ustc.edu.cn/anaconda/pkgs/main",
]
"https://repo.anaconda.com/pkgs/msys2" = [
"https://mirrors.ustc.edu.cn/anaconda/pkgs/msys2",
]
"https://repo.anaconda.com/pkgs/r" = [
"https://mirrors.ustc.edu.cn/anaconda/pkgs/r",
]

项目内 pyproject.toml

1
2
3
4
5
6
7
[tool.pixi.pypi-options]
extra-index-urls = [
"https://pypi.tuna.tsinghua.edu.cn/simple",
"https://pypi.org/simple",
]
index-url = "https://mirrors.aliyun.com/pypi/simple"
#no-build-isolation = ["chumpy"]

参考

[1] https://www.cnblogs.com/nolca/p/18919763