使用pip install 某些模块发生安装错误:
Traceback (most recent call last):
File "d:\python3.7.4\lib\site-packages\pip_vendor\urllib3\response.py", line 425, in _error_catcher
yield
File "d:\python3.7.4\lib\site-packages\pip_vendor\urllib3\response.py", line 507, in read
data = self._fp.read(amt) if not fp_closed else b""
File "d:\python3.7.4\lib\site-packages\pip_vendor\cachecontrol\filewrapper.py", line 62, in read
data = self.__fp.read(amt)
File "d:\python3.7.4\lib\http\client.py", line 457, in read
n = self.readinto(b)
File "d:\python3.7.4\lib\http\client.py", line 501, in readinto
n = self.fp.readinto(b)
File "d:\python3.7.4\lib\socket.py", line 589, in readinto
return self._sock.recv_into(b)
File "d:\python3.7.4\lib\ssl.py", line 1071, in recv_into
return self.read(nbytes, buffer)
File "d:\python3.7.4\lib\ssl.py", line 929, in read
return self._sslobj.read(len, buffer)
socket.timeout: The read operation timed out
During handling of the above exception, another exception occurred:
到网上搜了很多方法,包括使用管理员权限,修改pip main方法,都不行,后来我想应该就是简单的网速低导致断链的问题吧?pip可能不支持断点续传。
解决方法:
替换镜像地址
python pip 安装使用国内镜像源
<small style="font-size: 12px; letter-spacing: normal; color: rgb(171, 171, 171); display: block; text-align: right; font-family: Verdana, "Lucida Grande", Geneva, Arial, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial;">2019-07-04 10:55 微风阳光 阅读(12968) 评论(1) 编辑 [收藏](javascript:void(0))</small>
国内镜像源
清华:https://pypi.tuna.tsinghua.edu.cn/simple
阿里云:http://mirrors.aliyun.com/pypi/simple/
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
华中理工大学:http://pypi.hustunique.com/
山东理工大学:http://pypi.sdutlinux.org/
豆瓣:http://pypi.douban.com/simple/
临时使用
在使用pip的时候加参数-i https://pypi.tuna.tsinghua.edu.cn/simple
例如:pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pyspider,这样就会从清华这边的镜像去安装pyspider库。
一劳永逸
Linux下,修改 ~/.pip/pip.conf (没有就创建一个文件夹及文件。文件夹要加“.”,表示是隐藏文件夹)
内容如下:
|
[global]
index-url = http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com
|
windows下,直接在user目录中创建一个pip目录,如:C:\Users\xx\pip,新建文件pip.ini。内容同上。
本机win10操作系统,目录:C:\Users\DELL\AppData\Roaming\pip\pip.ini
遇到的问题
实际使用的时候,一开始使用清华的镜像,在安装时,总是提示
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
换了阿里的镜像之后,问题得到了解决。