常用镜像源 | Linux, anaconda, huggingface, pip 等

最近在一台受限的Ubuntu上配置和使用开源项目。由于该服务器暂时无法访问墙外网站,故找了很多镜像网站作为替代

1. pip(pypi) 清华镜像源

https://pypi.tuna.tsinghua.edu.cn/simple
使用方法:
终端命令

pip install 包名 -i https://pypi.tuna.tsinghua.edu.cn/simple

阿里云特定cuda源(用于下载特定CUDA版本的torch)

https://mirrors.aliyun.com/pytorch-wheels/cu113/

2. Anaconda 下载清华镜像源

https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/
使用方法(Linux)

wget  https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-2024.06-1-Linux-x86_64.sh

如果wget not found则先安装

sudo apt install wget

如果403 Forbidden则加上User-Agent

wget -U 'Mozilla' https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-2024.06-1-Linux-x86_64.sh

(参考[[https://www.cnblogs.com/haoliyou/p/17666790.html|此篇]])

3. GitHub 镜像源

https://gitclone.com
https://kkgithub.com
https://mirror.ghproxy.com
使用方法:在镜像网站找到对应代码仓库,复制地址

git clone 镜像地址/原地址
wget 镜像地址/原址  -p xxxx.pth

4. 更新submodule

有的项目会包含子模块需要更新,找到.gitmodule文件,将其中url = https://github.com/XXX/XXX.git改为
url = https://kkgithub.com/XXX/XXX.git
或者在本地更新完后上传

5. HuggingFace 镜像

原址常见错误: connectionerror: HTTPSConnectionPool(host='huggingface.co', port=443): Read timed out.
镜像地址 https://hf-mirror.com
换源方法(对于一些国外的开源项目无需手动更改代码):

pip install -U huggingface_hub
export HF_ENDPOINT=https://hf-mirror.com

补充:使用 hf_transfer加速下载

pip install hf_transfer
export HF_HUB_ENABLE_HF_TRANSFER=1 # 启用transfer

注意:使用国内镜像源+Transfer时可能会被限流而停止
(更多有关HuggingFace模型下载内容,可以参考[[https://zhuanlan.zhihu.com/p/663712983|这篇]])

5. conda install 增加国内镜像源

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud//pytorch/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --set show_channel_urls yes

参考自https://www.cnblogs.com/fireblackman/p/16422750.html


202409再更新:
由于服务器更换,转为使用CentOS 7,同样需要换源。

6. yum 换国内镜像源

在使用centOS内置的yum安装screen时报错:

Loaded plugins: fastestmirror, ovl
Determining fastest mirrors
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=container error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"
 One of the configured repositories failed (Unknown),
 and yum doesn't have enough cached data to continue. At this point the only
 safe thing yum can do is fail. There are a few ways to work "fix" this:

     1. Contact the upstream for the repository and get them to fix the problem.

     2. Reconfigure the baseurl/etc. for the repository, to point to a working
        upstream. This is most often useful if you are using a newer
        distribution release than is supported by the repository (and the
        packages for the previous distribution release still work).

     3. Run the command with the repository temporarily disabled
            yum --disablerepo=<repoid> ...
     4. Disable the repository permanently, so yum won't use it by default. Yum
        will then just ignore the repository until you permanently enable it
        again or use --enablerepo for temporary usage:
            yum-config-manager --disable <repoid>
        or
            subscription-manager repos --disable=<repoid>
     5. Configure the failing repository to be skipped, if it is unavailable.
        Note that yum will try to contact the repo. when it runs most commands,
        so will have to try and fail each time (and thus. yum will be be much
        slower). If it is a very temporary problem though, this is often a nice
        compromise:

故需要对yum换源

6.1 备份

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

6.2 下载镜像源

wget -O /etc/yum.repos.d/CentOS-Base.repo 地址 
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

6.3 清除缓存并更新

yum clean all
yum makecache

6.4 检查

尝试更新或者安装以检查yum是否正常工作

yum update

或 不更新yum内核

yum --exclude=kernel* update

参考自:[https://blog.csdn.net/m0_49605975/article/details/120039048]

posted @ 2024-07-10 13:53  Mactor  阅读(3866)  评论(0)    收藏  举报