美文网首页
python 国内镜像加速

python 国内镜像加速

作者: 木猫尾巴 | 来源:发表于2018-06-30 22:57 被阅读113次

[TOC]

原因

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

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

USER_BASEUSER_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 国内镜像加速

    [TOC] 原因 经常在使用Python的时候需要安装各种模块,而pip是很强大的模块安装工具但是由于国外官方默认...

  • python pip设置国内源

    参考链接:知乎,【Python pip 下载速度慢? Windows 设置 国内源,用 阿里云 国内镜像 加速】,...

  • 国内加速镜像

    nmp 淘宝https://registry.npm.taobao.org

  • 玩装Docker(3)-使用镜像

    镜像加速器 国内从Docker Hub拉取镜像有时会遇到困难,此时可以配置镜像加速器,国内很多云服务商都提供了国内...

  • Docker学习笔记(二)镜像加速器

    镜像加速器国内从 Docker Hub 拉取镜像有时会遇到困难,此时可以配置镜像加速器。Docker 官方和国内很...

  • Docker国内镜像加速镜像的下载

    Docker国内镜像加速镜像的下载 DaoCloud加速 访问DaoCloud官网进行注册账户。 点击顶上加速器,...

  • docker镜像加速器设置

    镜像加速器 国内访问Docker Hub可能会出现问题,如下图所示,拉取镜像超时,此时可以配置镜像加速器,国内很多...

  • Docker 镜像加速

    Docker 镜像加速 国内从 DockerHub 拉取镜像有时会遇到困难,此时可以配置镜像加速器。Docker ...

  • Docker镜像加速

    镜像加速器国内访问 Docker Hub 有时会遇到困难,此时可以配置镜像加速器。国内很多云服务商都提供了加速器服...

  • docker安装ubuntu 16.04

    1、docker 设置国内镜像源 国内加速地址有: Docker中国区官方镜像https://registry.d...

网友评论

      本文标题:python 国内镜像加速

      本文链接:https://www.haomeiwen.com/subject/dpmxuftx.html