使用python自带安装源速度很慢,连接不稳定容易出错。
本文将介绍使用清华大学安装源加速python3 安装软件包速度。以安装 numpy 为例。
加速分为临时和长期两种方法,首先演示临时使用方法。
#临时使用清华大学安装源安装numpy
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple numpy
长期使用需要修改配置文件,具体命令如下:
#升级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未作实际测试。方法如下
#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。
清华大学安装源也可以加速安装 anaconda 和部分 Conda 三方源。
#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 升级代码如下
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>
参考链接: