原因

经常在使用Python的时候需要安装各种模块,而pip是很强大的模块安装工具
但是由于国外官方默认pip访问速度慢,经常被墙,导致无法安装,所以我们最好是将自己使用的pip源更换一下,这样就能解决被墙导致的装不上库的烦恼

# 查看已经安装软件列表
$ pip freeze
# 查看当前配置
$ python -m site

USER_BASE 和 USER_SITE 其实就是用户自定义的启用Python脚本和依赖安装包的基础路径

镜像列表

http://mirrors.aliyun.com/pypi/simple/ //阿里
https://pypi.tuna.tsinghua.edu.cn/simple/ //清华
http://pypi.douban.com/ //豆瓣
http://pypi.hustunique.com/ //华中理工大学
http://pypi.sdutlinux.org/ //山东理工大学
http://pypi.mirrors.ustc.edu.cn/ //中国科学技术大学

国内使用得比较多并且速度比较快的是阿里的pip源或者清华大学,清华大学的是官网pypi的镜像

临时使用

pip的时候加参数 -i

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

常驻使用

Linux or macOS

修改 ~/.pip/pip.conf (没有就自己创建), 增加或者修改 index-url 至源

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
trusted-host = pypi.tuna.tsinghua.edu.cn
disable-pip-version-check = true
  • 豆瓣源使用
mkdir -p ~/.pip
echo -e '[global]\ntrusted-host = pypi.douban.com\nindex-url = http://pypi.douban.com/simple' > ~/.pip/pip.conf

windows

直接在user目录中创建一个pip目录,如:C:\Users\xx\pip

新建文件 pip.ini 内容

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
trusted-host = pypi.tuna.tsinghua.edu.cn
disable-pip-version-check = true
timeout = 120

或者使用豆瓣源

[global]
index-url = http://pypi.douban.com/simple
trusted-host = pypi.douban.com
disable-pip-version-check = true
timeout = 120
  • index-url 源,可以换成其他的源
  • trusted-host 添加源为可信主机,要不然可能报错
  • disable-pip-version-check 设置为true取消pip版本检查,排除每次都报最新的pip
  • timeout 超时设置
mkdir -p ~/.pip
echo -e '[global]\ntrusted-host = pypi.douban.com\nindex-url = http://pypi.douban.com/simple' > ~/.pip/pip.conf

windows

直接在user目录中创建一个pip目录,如:C:\Users\xx\pip

新建文件 pip.ini 内容

[global]
index-url = http://pypi.douban.com/simple
trusted-host = pypi.douban.com
disable-pip-version-check = true
timeout = 120

或者

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
trusted-host = pypi.tuna.tsinghua.edu.cn
disable-pip-version-check = true
timeout = 120

pip conf 参数说明

  • [install] 安装参数
  • install-option=--prefix= pip install的安装路径
  • [global] 表示为全局配置
  • index-url 源,可以换成其他的源
  • trusted-host 添加源为可信主机,要不然可能报错
  • disable-pip-version-check 设置为true取消pip版本检查,排除每次都报最新的pip
  • timeout 超时设置

python 国内镜像加速的更多相关文章

  1. python 使用pip安装使用国内镜像加速下载安装包的方法

    清华大学提供开源镜像站:https://mirrors.tuna.tsinghua.edu.cn/help/pypi/ pypi 镜像每 5 分钟同步一次. pip install 包的名字 == 版 ...

  2. pip安装库时报错,使用国内镜像加速

    pip install requests或pip --trusted-host pypi.python.org install requests报错: 原因:网上解释为网速太慢,或被防火墙 解决方法: ...

  3. docker学习(2) mac中docker-machine使用vmware fusion以及配置国内镜像加速

    一.前言 先回顾下上一节创建docker-machine的过程,默认情况下docker toolbox中的docker-machine使用virtual box创建虚拟机,KI首次启动时创建虚拟机的过 ...

  4. 安装使用yarn,使用国内镜像加速npm和yarn

    安装yarn https://yarnpkg.com/lang/zh-hans/docs/install/ 使用国内镜像加速npm和yarn 1. npm config set registry=ht ...

  5. Python pip 下载速度慢? Windows 设置 国内源,用 阿里云 国内镜像 加速

    pip 提供了对 Python 包的查找.下载.安装.卸载的功能,是非常方便的 Python 包管理工具.但是,令人苦恼的是 pip 在国内的下载速度非常慢,速度常常只有每秒几十 K,甚至才几 K,小 ...

  6. 使用国内镜像加速下载Android SDK

    本文转自:http://blog.kuoruan.com/24.html.感谢原作者. 什么是Android SDK SDK:(software development kit)软件开发工具包.被软件 ...

  7. python国内镜像源

    让python pip使用国内镜像 国内源: 清华:https://pypi.tuna.tsinghua.edu.cn/simple 阿里云:http://mirrors.aliyun.com/pyp ...

  8. Python 国内镜像源

    让 python pip 使用国内镜像源 国内镜像源: 清华:https://pypi.tuna.tsinghua.edu.cn/simple 阿里云:http://mirrors.aliyun.co ...

  9. python 国内镜像

    pipy国内镜像目前有: http://pypi.douban.com/  豆瓣 http://pypi.hustunique.com/  华中理工大学 http://pypi.sdutlinux.o ...

随机推荐

  1. php理解非对称SSL加密解密、验证及签名

    加密方式分为对称加密和非对称加密,对称加密只使用一个秘钥,加密和解密都使用该秘钥:非对称加密则使用一对秘钥,使用公钥加密,私钥解密. 需要通过原生的openssl_public_encrypt加密,o ...

  2. 2018-2019-2 20175213实验四 《Android开发基础》实验报告

    一.实验报告封面 课程:Java程序设计 班级:1752班 姓名:吕正宏 学号:20175213 指导教师:娄嘉鹏 实验日期:2019年5月14日 实验时间:13:45 - 21:00 实验序号:实验 ...

  3. 出席分布式事务Seata 1.0.0 GA典礼

    前言 图中那个红衣服的就是本人 什么是分布式事务 分布式事务就是指事务的参与者.支持事务的服务器.资源服务器以及事务管理器分别位于不同的分布式系统的不同节点之上. 简单的说,就是一次大的操作由不同的小 ...

  4. 读取 appsettings.json

    Appsettings.json 配置: 个配置文件就是一个json文件,并且是严格的json文件,所有的属性都需要添加“”引号.下图是一个常规的代码示例: {"UrlString" ...

  5. 如何录制视频生成GIF动态图?

    前言 在分享文章时有些知识不好讲清,就打算用gif图来展示,可是在网上找了几个录视频的工具都要会员才可以生成gif动态图,很是郁闷,不过苦苦寻找后,发现LICEcap很好用,可以很方便的生成gif动态 ...

  6. 私有IP地址

    私有IP地址: 在ABC三类网络中,如下三段网络地址为私有IP地址,如何人都可以自行在自己的局域网中使用这些IP地址. A类私有:10.0.0.1----10.255.255.254 B类私有:172 ...

  7. Action.c(28): Error -27796: Failed to connect to server "xxxx": [10060] Connection timed out

    Error -27796: Failed to connect to server "125.93.51.230:8080": [10061] Connection refused ...

  8. [已解决]报错: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/Users/mac/Ana

    报错代码: pip3 install gerapy 报错内容: Could not install packages due to an EnvironmentError: [Errno 13] Pe ...

  9. WebSocket 网页聊天室

    先给大家开一个原始的websocket的连接使用范例 <?php /* * recv是从套接口接收数据,也就是拿过来,但是不知道是什么 * read是读取拿过来的数据,就是要知道recv过来的是 ...

  10. Fix invisible cursor issue in Ubuntu 13.10

    Fix invisible cursor issue in Ubuntu 13.10 Fixing this problem is rather too easy. Open a terminal ( ...