在安装python库,在网络很差的状况会遇到python
raise ReadTimeoutError(self._pool, None, 'Read timed out.')
ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.ubuntu
解决办法1:延长timeout时间vim
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替换你所须要的库就行windows
解决办法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/工具
注意:新版ubuntu要求使用https源。阿里云
设置方法:(以清华镜像为例,其它镜像同理)
(1)临时使用:
能够在使用pip的时候,加上参数-i和镜像地址(如
https://pypi.tuna.tsinghua.edu.cn/simple),
例如:pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pandas,这样就会从清华镜像安装pandas库。url
(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。
在清华源和中科大源之间自行选择
命令行中直接使用如下命令
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的镜像
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
conda config --remove-key channels
将以上配置文件写在~/.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