升级 pip : python -m pip install --upgrade pip,socket.timeout: The read operation timed out 加入超时处理方法

WARNING: You are using pip version 19.3.1; however, version 20.0.2 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

警告:您正在使用pip 19.3.1版本;但是,版本20.0.2是可用的。

您应该考虑通过“ python -m pip install --upgrade pip ”命令进行升级。

 

1、在cmd命令窗口中输入提示的命令即可:

python -m pip install --upgrade pip

 2、如果遇到如下 超时 socket.timeout 问题:

G:\works\PythonCharmPre>python -m pip install --upgrade pip
Collecting pip
  Downloading https://files.pythonhosted.org/packages/54/0c/d01aa759fdc501a58f431eb594a1
7495f15b88da142ce14b5845662c13f3/pip-20.0.2-py2.py3-none-any.whl (1.4MB)
     |█▌                              | 61kB 1.8kB/s eta 0:12:54ERROR: Exception:
Traceback (most recent call last):
  File "C:\Users\Acer\AppData\Local\Programs\Python\Python38\lib\site-packages\pip\_vend
or\urllib3\response.py", line 425, in _error_catcher
    yield
  File "C:\Users\Acer\AppData\Local\Programs\Python\Python38\lib\site-packages\pip\_vend
or\urllib3\response.py", line 507, in read
    data = self._fp.read(amt) if not fp_closed else b""
  File "C:\Users\Acer\AppData\Local\Programs\Python\Python38\lib\site-packages\pip\_vend
or\cachecontrol\filewrapper.py", line 62, in read
    data = self.__fp.read(amt)
  File "C:\Users\Acer\AppData\Local\Programs\Python\Python38\lib\http\client.py", line 4
54, in read
    n = self.readinto(b)
  File "C:\Users\Acer\AppData\Local\Programs\Python\Python38\lib\http\client.py", line 4
98, in readinto
    n = self.fp.readinto(b)
  File "C:\Users\Acer\AppData\Local\Programs\Python\Python38\lib\socket.py", line 669, i
n readinto
    return self._sock.recv_into(b)
  File "C:\Users\Acer\AppData\Local\Programs\Python\Python38\lib\ssl.py", line 1241, in
recv_into
    return self.read(nbytes, buffer)
  File "C:\Users\Acer\AppData\Local\Programs\Python\Python38\lib\ssl.py", line 1099, in
read
    return self._sslobj.read(len, buffer)
socket.timeout: The read operation timed out

超时的原因是:

(1)国外的资源,下载本身比较慢,自己网络可能还是一般般的网速

(2)在cmd命令窗口输入pip , 可以看到默认的超时的时间是 15 秒

 

百度看别人的方法有写或者修改 pip.conf 文件的,也有用镜像的,我由于不知道pip.conf 的文件写在哪,二镜像太麻烦。

(以上两种方法具体实现在这:https://www.cnblogs.com/shenh/p/9444103.html

之前本来想有不有那种直接把 timeout 的时间永久改长的,不过没有找到方法。

就找了个最简单的方法,设置单个的超时下载超时时间:

可以在cmd命令窗口直接输入,也可以在PyCharm 的Terminal中输入:(timeout 的时间可以自己定义)

(请看完再决定这个方法用不用,虽然简单)反正最后是成功了

pip --default-timeout=900 install --upgrade pip

 

我就边写这个博客边等它下完了,谁知道来个ERROR :

意思是:要修改pip,请运行以下命令:

 

 

然后我就重新改了一下命令:

(也许您可以直接试一下直接就输入这一条?我也不确定,不过我想如果后面运行不行的话我们可以讨论一下)

python -m pip --default-timeout=900 install --upgrade pip

 

 

然后我的卡了很久没有反应,可能是我网络的原因?我等了一会还是没有反应(也许您可以多等一下),就在cmd命令行中运行了一般的升级命令,马上cmd命令窗口就有反应了

python -m pip install --upgrade pip

输入 pip list 可以看到pip的版本已经是20.0.2了

过了一会看到Pycharm中最后也出现了相同的提示,但是这个提示前面很多报红,有点莫名其妙:

 

  • 11
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论
当使用pip install -r requirements.txt进行安装时,如果遇到超时的情况,可以尝试以下几个解决方法: 1. 增加默认超时时间:使用--default-timeout参数可以设置pip命令的默认超时时间。例如:pip install --default-timeout=1000 -r requirements.txt会将超时时间设置为1000秒。 2. 关闭缓存:使用--no-cache-dir参数可以关闭缓存,从而避免因为缓存问题导致超时。例如:pip install --no-cache-dir -r requirements.txt。 3. 更新requirements.txt文件:如果requirements.txt文件中的依赖项已经过时,可能会导致超时。可以使用pipreqs命令更新requirements.txt文件,确保其中的依赖项是最新的。首先使用pip install pipreqs安装pipreqs,然后使用pipreqs命令生成requirements.txt文件。例如:pipreqs . --encoding=utf8 --force生成requirements.txt文件。 4. 使用阿里云镜像源:可以指定使用阿里云镜像源来下载依赖项,从而加快下载速度并减少超时的可能性。例如:pip install -r requirements.txt -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com。 通过以上方法,您可以尝试解决pip install -r requirements.txt超时的问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [pip install -r requirements.txt安装超时解决方法](https://blog.csdn.net/weixin_43116723/article/details/104139541)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [pip install -r requirements.txt 超时 以及WARNING: Retrying (Retry(total=X ... 解决方案](https://blog.csdn.net/weixin_42455006/article/details/121957633)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

懒笑翻

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值