python3 和 anaconda 使用國內(清華大學)源加速安裝軟件包

最新消息:清華大學和中科大等安裝源已取消加速功能。https://www.oschina.net/news/106265/ustc-close-anaconda-servicepython

使用python自帶安裝源速度很慢,鏈接不穩定容易出錯。windows

本文將介紹使用清華大學安裝源加速python3 安裝軟件包速度。以安裝 numpy 爲例。測試

加速分爲臨時和長期兩種方法,首先演示臨時使用方法。ui

#臨時使用清華大學安裝源安裝numpy
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple numpy

長期使用須要修改配置文件,具體命令以下:url

#升級pip
pip install pip -U
#python -m pip install --upgrade pip
#修改pip配置文件,其餘安裝源能夠使用相似方法,只須要修改末尾安裝源
#部分Windows 和Linux能夠直接執行命令,以您本機具體運行結果爲準
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
#兩條任選一條執行
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/

pip 和 pip3 並存時,只需修改 ~/.pip/pip.conf。本方法適合Linux和Windows,Mac未做實際測試。方法以下.net

#Windows版本配置過程
Windows PowerShell
版權全部 (C) Microsoft Corporation。保留全部權利。

PS C:\Windows\system32> pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
Writing to C:\Users\legion\AppData\Roaming\pip\pip.ini
#演示用,Linux一樣適用,只需任選一條執行
PS C:\Windows\system32> pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
Writing to C:\Users\legion\AppData\Roaming\pip\pip.ini
PS C:\Windows\system32>

#也能夠直接修改已有文件
#pip.ini內容1
[global]
index-url = https://mirrors.aliyun.com/pypi/simple/

#pip.ini內容2
[global]
index-url = https://mirrors.aliyun.com/pypi/simple/

[install]
trusted-host=mirrors.aliyun.com

須要指出,部分複雜python軟件包須要VC14等軟件包,推薦使用anaconda。code

清華大學安裝源也能夠加速安裝 anaconda 和部分 Conda 三方源。ip

#anaconda 官方安裝源
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 --set show_channel_urls yes
#部分conda安裝源
#Conda Forge
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
#msys2
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
#bioconda
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
#menpo
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/menpo/
#pytorch
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
# for legacy win-64
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/peterjc123/

Anaconda 升級代碼以下get

C:\windows\system32>conda upgrade --all
Solving environment: done

## Package Plan ##

  environment location: C:\ProgramData\Anaconda3


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    pluggy-0.7.1               |             py_0          14 KB  https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
    blosc-1.14.2               |       h6538335_0         1.7 MB  https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
    ipython-6.5.0              |           py36_0         1.1 MB  https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
    pytest-3.7.0               |           py36_0         329 KB  https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
    conda-4.5.9                |           py36_0         654 KB  https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
    botocore-1.10.66           |             py_0         2.7 MB  https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
    pyasn1-0.4.4               |             py_0          46 KB  https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
    boto3-1.7.66               |             py_0          64 KB  https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
    ------------------------------------------------------------
                                           Total:         6.6 MB

The following packages will be UPDATED:

    blosc:    1.14.0-h6538335_1 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge --> 1.14.2-h6538335_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
    boto3:    1.7.65-py_0       https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge --> 1.7.66-py_0       https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
    botocore: 1.10.65-py_0      https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge --> 1.10.66-py_0      https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
    conda:    4.5.8-py36_1      https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge --> 4.5.9-py36_0      https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
    ipython:  6.4.0-py36_0      https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge --> 6.5.0-py36_0      https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
    pluggy:   0.6.0-py_0        https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge --> 0.7.1-py_0        https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
    pyasn1:   0.4.3-py_0        https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge --> 0.4.4-py_0        https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
    pytest:   3.6.4-py36_0      https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge --> 3.7.0-py36_0      https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge

Proceed ([y]/n)? y


Downloading and Extracting Packages
pluggy-0.7.1         |   14 KB | ###################################### | 100%
blosc-1.14.2         |  1.7 MB | ###################################### | 100%
ipython-6.5.0        |  1.1 MB | ###################################### | 100%
pytest-3.7.0         |  329 KB | ###################################### | 100%
conda-4.5.9          |  654 KB | ###################################### | 100%
botocore-1.10.66     |  2.7 MB | ###################################### | 100%
pyasn1-0.4.4         |   46 KB | ###################################### | 100%
boto3-1.7.66         |   64 KB | ###################################### | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done

C:\windows\system32>conda upgrade --all
Solving environment: done

# All requested packages already installed.


C:\windows\system32>

參考連接:it

https://mirrors.tuna.tsinghua.edu.cn/help/anaconda/

https://mirrors.tuna.tsinghua.edu.cn/help/pypi/

https://opsx.alibaba.com/mirror

相關文章
相關標籤/搜索