更换 conda、pip、apt 镜像源为国内镜像源

目录

  • 一、conda 更换国内镜像源
    • 1.1 国内源
      • 1.1.1 清华源(2019年停止服务,不知道会不会恢复)
      • 1.1.2 中科大源(推荐)
    • 1.2 Windows
    • 1.3 Linux
    • 1.4 查看已经安装过的镜像源
    • 1.5 删除源
    • 1.6 换回默认源
  • 二、pip 更换国内镜像源
    • 2.1 **国内镜像源**
    • 2.2 临时源
    • 2.3 永久源
      • 2.3.1 Linux
      • 2.3.2 Windows
  • 三、apt 更换国内镜像源
    • 3.1 修改源列表文件
    • 3.2 通过图形化界面修改源

一、conda 更换国内镜像源

1.1 国内源

1.1.1 清华源(2019年停止服务,不知道会不会恢复)

https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/

1.1.2 中科大源(推荐)

https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/
https://mirrors.ustc.edu.cn/anaconda/cloud/msys2/
https://mirrors.ustc.edu.cn/anaconda/cloud/bioconda/
https://mirrors.ustc.edu.cn/anaconda/cloud/menpo/

1.2 Windows

  • 添加清华源

    conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
    conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge 
    conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
    conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
    
    # 设置搜索时显示通道地址
    conda config --set show_channel_urls yes
    
  • 添加中科大源

    conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
    conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
    conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/
    conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/msys2/
    conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/bioconda/
    conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/menpo/
    
    conda config --set show_channel_urls yes
    

1.3 Linux

  • 创建并打开配置文件

    vim ~/.condarc
    
  • 安装清华源

    channels:
      - https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
      - https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/
      - defaults
    show_channel_urls: true
    

1.4 查看已经安装过的镜像源

conda config --show

1.5 删除源

conda config --remove channels url地址

1.6 换回默认源

conda config --remove-key channels

二、pip 更换国内镜像源

2.1 国内镜像源

  • 阿里云: https://mirrors.aliyun.com/pypi/simple/

  • 中国科技大学: https://pypi.mirrors.ustc.edu.cn/simple/

  • 豆瓣(douban): https://pypi.douban.com/simple/

  • 清华大学: https://pypi.tuna.tsinghua.edu.cn/simple/

  • 华中科技大学:https://pypi.hustunique.com/

2.2 临时源

  • 安装命令后接 -i url 即可,如:用清华镜像下载pandas
pip install pandas -i https://pypi.tuna.tsinghua.edu.cn/simple

2.3 永久源

2.3.1 Linux

  • 创建配置文件

    vim ~/.pip/pip.conf
    
  • 添加以下内容

    [global]
    index-url = https://pypi.tuna.tsinghua.edu.cn/simple
    

2.3.2 Windows

  • 修改%HOMEPATH%\pip\pip.ini文件

  • %HOMEPATH%通常为C:\Users\xx

  • 通常需要新建文件夹pip,然后新建文件pip.ini,ini文件可以用记事本打开和编辑,在pip.ini文件中输入以下内容(以清华镜像为例):

    [global]
    index-url = https://pypi.tuna.tsinghua.edu.cn/simple
    [install]
    trusted-host = pypi.tuna.tsinghua.edu.cn
    

三、apt 更换国内镜像源

3.1 修改源列表文件

  • 备份源列表

    sudo cp /etc/apt/sources.list  /etc/apt/sources.list_save
    
  • 打开源列表

    sudo vim /etc/apt/sources.list  
    
  • 修改源列表,将以下源复制进去

    • 阿里源
    deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
    
    deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
    
    deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
    
    deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
    
    deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
    
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
    
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
    
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
    
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
    
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
    
    • 中科大源
    deb https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
    
    deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
    
    deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
    
    deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
    
    deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
    
    deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
    
    deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
    
    deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
    
    deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
    
    deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
    
    • 清华源
    deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
    
    deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
    
    deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
    
    deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
    
    deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
    
    deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
    
    deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
    
    deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
    
    deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
    
    deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
    
    • 163源
    deb http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse
    
    deb http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse
    
    deb http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse
    
    deb http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse
    
    deb http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse
    
    deb-src http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse
    
    deb-src http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse
    
    deb-src http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse
    
    deb-src http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse
    
    deb-src http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse
    
  • 更新本地apt源

    sudo apt update
    

3.2 通过图形化界面修改源

  • 进入桌面,找到 system setting
  • 选择 Software & Updates
  • 在Download from 处选择 other , 找到china,选择合适的源即可

你可能感兴趣的:(Linux,Windows,Python,conda,pip,linux)