先觀察清華源的conda配置檔案:
channels:
- defaults
show_channel_urls: true
default_channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
pytorch-lts: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
deepmodeling: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/
頻道的結論
我沒有看官方的文件,太多了,直接實踐吧。
結論1:頻道名其實就是目錄名。比如:pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
在cloud目錄下,必然有一個pytorch目錄,這就是頻道的實現方式,用目錄名對映頻道名。
頻道的優先順序
猜測就是開頭的channel按出現的順序定義的優先順序。
比如我想定義:nvidia, pytorch, defaults這個優先順序順序,我就如下定義:
channels:
- nvidia
- pytorch
- defaults
檢測正確性
先把配置檔案 .condarc 改為如下:
channels:
- nvidia
- pytorch
- pytorch-lts
- defaults
show_channel_urls: true
default_channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
custom_channels:
nvidia: https://mirrors.sustech.edu.cn/anaconda-extra/cloud
pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
pytorch-lts: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
1、檢查是否能被正確讀取:conda config --show
,如果在輸出能看到上述配置,說明被正確讀取了。
2、檢查優先順序是否正確,搜尋一個多個頻道都存在的包,列印出來,看看列印先後的順序,就知道優先順序了。
conda search cuda-cudart=12.4.127 --json
輸出:
{
"cuda-cudart": [
{
"arch": null,
"build": "0",
"build_number": 0,
"channel": "https://mirrors.sustech.edu.cn/anaconda-extra/cloud/nvidia/linux-64",
"constrains": [],
"depends": [],
"fn": "cuda-cudart-12.4.127-0.tar.bz2",
"md5": "3f783f2954e59ff9f8df2b2dbc854266",
"name": "cuda-cudart",
"platform": null,
"sha256": "5b229895b7684dfe8f923742036e15ebf9a6a0d304aa32e3792c12931a94c82b",
"size": 203174,
"subdir": "linux-64",
"timestamp": 1710544194723,
"url": "https://mirrors.sustech.edu.cn/anaconda-extra/cloud/nvidia/linux-64/cuda-cudart-12.4.127-0.tar.bz2",
"version": "12.4.127"
},
{
"arch": null,
"build": "h99ab3db_0",
"build_number": 0,
"channel": "https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/linux-64",
"constrains": [],
"depends": [
"__glibc >=2.17,<3.0.a0",
"cuda-cudart_linux-64 12.4.127 hd681fbe_0",
"cuda-version >=12.4,<12.5.0a0",
"libgcc-ng >=11.2.0",
"libstdcxx-ng >=11.2.0"
],
"fn": "cuda-cudart-12.4.127-h99ab3db_0.conda",
"legacy_bz2_md5": "bbd342944f4c340faf2a7c40afaf9981",
"legacy_bz2_size": 21372,
"license": "LicenseRef-NVIDIA-End-User-License-Agreement",
"md5": "96db1f9a35b0ae5b516c4baebb57244a",
"name": "cuda-cudart",
"platform": null,
"sha256": "2dead6f0b62112e0c270aeb4ff766559beaf85cae3bf480fa0a76ecf2c78988b",
"size": 21378,
"subdir": "linux-64",
"timestamp": 1714768620619,
"url": "https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/linux-64/cuda-cudart-12.4.127-h99ab3db_0.conda",
"version": "12.4.127"
}
]
}
加入引數 --json 就是為了輸出更全的資訊,看到 南方科技大學的頻道在前,預設頻道在後,說明正確設定了優先順序。
配置修改說明
預設頻道有 3 個,分別是 main,r,msys2應該是對應 python語言,r語言,msys2系統的包。
我是 ubuntu24.04 系統,r 和 msys2 暫時不用,刪掉。
自定義頻道,保留pytorch,pytorch-lts,其他都暫時用不到,刪掉。