原因

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

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

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

镜像列表

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

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

临时使用

pip的时候加参数 -i

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

常驻使用

Linux or macOS

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

  1. [global]
  2. index-url = https://pypi.tuna.tsinghua.edu.cn/simple
  3. trusted-host = pypi.tuna.tsinghua.edu.cn
  4. disable-pip-version-check = true
  • 豆瓣源使用
  1. mkdir -p ~/.pip
  2. 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 内容

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

或者使用豆瓣源

  1. [global]
  2. index-url = http://pypi.douban.com/simple
  3. trusted-host = pypi.douban.com
  4. disable-pip-version-check = true
  5. timeout = 120
  • index-url 源,可以换成其他的源
  • trusted-host 添加源为可信主机,要不然可能报错
  • disable-pip-version-check 设置为true取消pip版本检查,排除每次都报最新的pip
  • timeout 超时设置
  1. mkdir -p ~/.pip
  2. 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 内容

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

或者

  1. [global]
  2. index-url = https://pypi.tuna.tsinghua.edu.cn/simple
  3. trusted-host = pypi.tuna.tsinghua.edu.cn
  4. disable-pip-version-check = true
  5. 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. angualr项目引入容联 七陌7mroo

    最近项目要求在注册页面增加客服服务浮窗,各种查找资料准备采用7moor来实现.现记录一下实现过程,便于后期查看: 引入7moor浮窗有两种方式: 1.h5方式,这种情况一般是单独打开新页面即可: 直接 ...

  2. 启动Nginx、查看nginx进程、nginx帮助命令、Nginx平滑重启、Nginx服务器的升级

    1.启动nginx的方式: cd /usr/local/nginx ls

  3. react教程 — 性能优化

    参考:https://segmentfault.com/a/1190000007811296?utm_medium=referral&utm_source=tuicool  或  https: ...

  4. [NOIP模拟20]题解

    来自达哥的问候…… A.周 究级难题,完全不可做QAQ #include<cstdio> #include<iostream> #include<cstring> ...

  5. js中打地鼠游戏

    <!DOCTYPE html><html lang=""><head> <mata charset = "utf-8" ...

  6. 服务器上的 IPProxy代理设置

    1.window 平台 CCProxy 安装包 传送门: http://www.xue51.com/soft/2794.html 该页面详细的说明了ccproxy怎么安装.怎么破jie.... 下面老 ...

  7. git 小错误

    (一)在本地直接修改文件,提交后出现(master|REBASE 1/2).由于文件冲突所以导致各种报错. 在git pull --rebase origin master后 error: Pulli ...

  8. centos查看磁盘空间大小

    查看磁盘空间大小 df -h 查看当前文件夹所有文件大小 du -sh 查看指定文件夹大小 du -h /data 查看指定文件夹下所有文件的大小 du -h /data/ 查看指定文件大小 du - ...

  9. Python 进阶_函数式编程

    目录 目录 函数式编程 Python 函数式编程的特点 高阶函数 匿名函数 lambda 函数式编程相关的内置函数 filter 序列对象过滤器 map reduce 折叠 自定义的排序函数 最后 函 ...

  10. maven(二),Linux安装maven3.5.3及配置

    Linux系统,ubuntu-16.04.4,安装maven3.5.3 一.创建文件夹 注意Linux用户,这个如果不是root用户,命令前面需要加:sudo //创建一个目录 mkdir /usr/ ...