解决方法,设置超时时间

pip --default-timeout=100 install -U Pillow

安装时指定源(--index-url)

#例如安装scipy时使用豆瓣的源
pip install --index-url https://pypi.douban.com/simple scipy

PyPI使用国内源

 

通过几次 pip 的使用,对于默认的 pip 源的速度实在无法忍受,于是便搜集了一些国内的pip源,如下:

阿里云 http://mirrors.aliyun.com/pypi/simple/

中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/

豆瓣(douban) http://pypi.douban.com/simple/

清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/

中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/

使用方法很简单,直接 -i 加 url 即可!如下:

1
# pip install web.py -i http://pypi.douban.com/simple

如果有如下报错:

请使用命令:

1
# pip install web.py -i http://pypi.douban.com/simple --trusted-host pypi.douban.com

如果想配置成默认的源,方法如下:

需要创建或修改配置文件(一般都是创建),

linux的文件在~/.pip/pip.conf,

windows

win10: %appdata%下

Win7: C:\Users\xxx\  或  %USERPROFILE%下

   目录下新建pip文件夹,在pip文件夹下新建pip.ini文件

修改内容为:

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

这样在使用pip来安装时,会默认调用该镜像。

临时使用其他源安装软件包的python脚本如下:

1
2
3
4
5
6
7
#!/usr/bin/python
 
import os
 
package = raw_input("Please input the package which you want to install!\n")
command = "pip install %s -i http://pypi.mirrors.ustc.edu.cn/simple --trusted-host pypi.mirrors.ustc.edu.cn" % package
os.system(command)

也可以使用读入文件进行安装。
ok,仅以记录一下,以便于后期查阅!

------日期:2018年11月1日 增加Python配置pip默认源脚本,复制到pip_source.py,执行即可。

#!/usr/bin/python
# coding: utf-8 import platform
import os os_type = platform.system()
if "Linux" == os_type:
fileDirPath = "%s/.pip" % os.path.expanduser('~')
filePath = "%s/pip.conf" % fileDirPath
if not os.path.isdir(fileDirPath):
os.mkdir(fileDirPath)
fo = open(filePath, "w")
fo.write(
"[global]\nindex-url=https://pypi.tuna.tsinghua.edu.cn/simple/\n[install]\ntrusted-host=pypi.tuna.tsinghua.edu.cn\n")
fo.close()
print "Configuration is complete"
elif "Windows" == os_type:
fileDirPath = "%s\\pip" % os.path.expanduser('~')
filePath = "%s\\pip.ini" % fileDirPath
if not os.path.isdir(fileDirPath):
os.mkdir(fileDirPath)
fo = open(filePath, "w")
fo.write(
"[global]\nindex-url=https://pypi.tuna.tsinghua.edu.cn/simple/\n[install]\ntrusted-host=pypi.tuna.tsinghua.edu.cn\n")
fo.close()
print "Configuration is complete"
else:
exit("Your platform is unknow!")
 

pip Read timed out 和 pip 源的更多相关文章

  1. 为你的pip更换一个国内的镜像源

    为你的pip更换一个国内的镜像源 是否常常为pypi官网被无故和谐掉导致pip不能下载python的各个包而痛心疾首? 是否常常在深夜里看着pip install 下载包的速度慢如乌龟而长吁短叹? 是 ...

  2. pip命令使用国内pypi镜像源加速在线安装

    参考:http://www.cnblogs.com/yudar/p/4444097.html 用easy_install和pip来安装第三方库很方便 它们的原理其实就是从Python的官方源pypi. ...

  3. pip安装报错处理+PyPi源切换教程

    一.pip安装出错类型 1.1 pip版本过旧导致不能安装 报错提示: You are using pip version 9.0.3, however version 10.0.1 is avail ...

  4. pip操作以及window和虚拟机中为pip更换一个国内的镜像源的方法

    前言 在学习PyQt5的过程中,参考王硕和孙洋洋的PyQt5快速开发与实战中,看到的关于Python开发技巧与实战,觉得挺好的 所以将其摘抄了下来方便阅读.之后还有一个关于更换pip镜像源的方法,方便 ...

  5. pip 安装包 使用国内镜像源

    1.pipy国内镜像目前有: 阿里云  http://mirrors.aliyun.com/pypi/simple/  中国科技大学  https://pypi.mirrors.ustc.edu.cn ...

  6. python 安装模块之pip install +模块名的换源写法

    1.采用国内源,加速下载模块的速度2.常用pip源(上一篇博客介绍过):– 豆瓣:https://pypi.douban.com/simple– 阿里:https://mirrors.aliyun.c ...

  7. 修改apt,pip,npm为国内镜像源

    apt 原文件备份 sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak 编辑源列表文件 sudo vim /etc/apt/sources. ...

  8. socket.timeout: The read operation timed out 更改pip源至国内镜像,显著提升下载速度

    出现socket.timeout: The read operation timed out  错误的时候,可能是pip源不稳定,改改试试看!  经常在使用Python的时候需要安装各种模块,而pip ...

  9. pip安装模块使用国内镜像源加速安装

    今天在安装Python模块matplotlib的时候,一直安装不成功,老是提示“socket.timeout: The read operation timed out”或者“Read timed o ...

随机推荐

  1. February 20th, 2018 Week 8th Tuesday

    Receive without conceit, release without struggle. 接受时,不狂妄:放手时,不犹豫. How to understand this quote? Do ...

  2. JavaScript对象原型写法详解

        体现对象原型分步式写法 //原型分步式写法 //构造函数 function Person(){} //对象原型 Person.prototype.name = 'Avensatr'; Pers ...

  3. win32gui.Findwindow(parm1,parm2)查找窗口的句柄方法

    介绍之前先让大家了解一下win32gui的模块用法 和 获取窗口类名工具 使用Python时,有时也会要操作到系统窗口的一些东西,下面就介绍win32gui.Findwindow(param1,par ...

  4. MYSQL的binlog日志

    binlog 基本认识 MySQL的二进制日志以事件形式,记录了所有的DDL和DML(除了数据查询语句)语句,及语句执行消耗时间. MySQL的二进制日志是事务安全型的,是MySQL最重要的日志. b ...

  5. Servlet工作原理解析(tomcat7、嵌入式服务器)

      目录 Servlet 容器Tomcat Servlet 容器的启动过程 Web 应用的初始化工作 Servlet 体系结构 创建 Servlet 对象(如何被加载) 初始化 Servlet(如何被 ...

  6. flask的migrate

    https://blog.csdn.net/kevin_qq/article/details/51777190 这个方法可以: https://www.cnblogs.com/caicairui/p/ ...

  7. centos7下安装docker(15.6docker跨主机网络---Weave)

    Weave是weaveworks开发的容器网络解决方案.weave创建的虚拟网络可以将部署在多个主机上的容器连接起来.对于容器来说,weave就像一个巨大的网络交换机,容器可以直接通信,无需NAT和端 ...

  8. java中的闭包

    闭包(Closure)是一种能被调用的对象,它保存了创建它的作用域的信息 public class Programmer { private String name; public Programme ...

  9. [Python] timeit测试代码运行效率

    python中有两种方法判断一个数是不是偶数或者奇数: In [29]: 3&1 Out[29]: 1 In [30]: 3%2 Out[30]: 1 In [31]: 4&1 Out ...

  10. Spring Security(二十二):6.4 Method Security

    From version 2.0 onwards Spring Security has improved support substantially for adding security to y ...