pip安装库时出现Read timed out.解决办法 您所在的位置:网站首页 怎么安装psutil pip安装库时出现Read timed out.解决办法

pip安装库时出现Read timed out.解决办法

2023-12-16 15:20| 来源: 网络整理| 查看: 265

在安装python库,在网络不好的情况会遇到

raise ReadTimeoutError(self._pool, None, 'Read timed out.') ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.

解决办法1:延长timeout时间

raise ReadTimeoutError(self._pool, None, 'Read timed out.') ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out. pip --default-timeout=100 install Package

将Package替换你所需要的库就行

解决办法2:换源,将pip源更换到国内镜像

#例如安装scipy时使用豆瓣的源 pip install --index-url https://pypi.douban.com/simple scipy #使用清华大学的源 pip install -i https://pypi.tuna.tsinghua.edu.cn/simple –upgrade tensorflow-gpu

将pip源更换到国内镜像 用pip管理工具安装库文件时,默认使用国外的源文件,因此在国内的下载速度会比较慢,可能只有50KB/s。幸好,国内的一些顶级科研机构已经给我们准备好了各种镜像,下载速度可达2MB/s。 其中,比较常用的国内镜像包括:

(1)阿里云 http://mirrors.aliyun.com/pypi/simple/ (2)豆瓣http://pypi.douban.com/simple/ (3)清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/ (4)中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/ (5)华中科技大学http://pypi.hustunique.com/

(6)网易 http://mirrors.163.com/pypi/simple/

注意:新版ubuntu要求使用https源。

设置方法:(以清华镜像为例,其它镜像同理) (1)临时使用: 可以在使用pip的时候,加上参数-i和镜像地址(如 https://pypi.tuna.tsinghua.edu.cn/simple), 例如:pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pandas,这样就会从清华镜像安装pandas库。

(2)永久修改,一劳永逸: (a)Linux下,修改 ~/.pip/pip.conf (没有就创建一个文件夹及文件。文件夹要加“.”,表示是隐藏文件夹) 内容如下:

[global] index-url = https://pypi.tuna.tsinghua.edu.cn/simple [install] trusted-host = https://pypi.tuna.tsinghua.edu.cn

(b) windows下,直接在user目录中创建一个pip目录,如:C:\Users\xx\pip,然后新建文件pip.ini,即 %HOMEPATH%\pip\pip.ini,在pip.ini文件中输入以下内容(以豆瓣镜像为例):

[global] index-url = http://pypi.douban.com/simple [install] trusted-host = pypi.douban.com

创建pip.ini文件可以用文本编辑器,例如 sublime text3。

anaconda conda 切换为国内源 windows下

在清华源和中科大源之间自行选择

1 添加清华源

命令行中直接使用以下命令

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/ # 设置搜索时显示通道地址 conda config --set show_channel_urls yes

注意如果需要pytorch, 还需要添加pytorch的镜像

2 添加中科大源 conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/ conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/ conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/ conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/msys2/ conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/bioconda/ conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/menpo/ conda config --set show_channel_urls yes 3 切换回默认源 conda config --remove-key channels Linux下

将以上配置文件写在~/.condarc中vim ~/.condarc

channels: - https://mirrors.ustc.edu.cn/anaconda/pkgs/main/ - https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/ - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ - defaults show_channel_urls: true 其他

使用如下命令可以查看库的各个版本及平台

anaconda search -t conda tensorflow

 

anaconda show 包名, 可以查看该包名的安装命令 

anaconda show anaconda/tensorflow-gpu



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有