当前位置:   article > 正文

pip安装python库出现Read timed out解决办法_pip install read time out

pip install read time out

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

问题如下

pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.
  • 1

解决办法

查看pip --help

Usage:   
  pip <command> [options]

Commands:
  install                     Install packages.
  download                    Download packages.
  uninstall                   Uninstall packages.
  freeze                      Output installed packages in requirements format.
  list                        List installed packages.
  show                        Show information about installed packages.
  check                       Verify installed packages have compatible dependencies.
  config                      Manage local and global configuration.
  search                      Search PyPI for packages.
  cache                       Inspect and manage pip's wheel cache.
  index                       Inspect information available from package indexes.
  wheel                       Build wheels from your requirements.
  hash                        Compute hashes of package archives.
  completion                  A helper command used for command completion.
  debug                       Show information useful for debugging.
  help                        Show help for commands.

General Options:
  -h, --help                  Show help.
  --debug                     Let unhandled exceptions propagate outside the main
                              subroutine, instead of logging them to stderr.
  --isolated                  Run pip in an isolated mode, ignoring environment
                              variables and user configuration.
  -v, --verbose               Give more output. Option is additive, and can be used up
                              to 3 times.
  -V, --version               Show version and exit.
  -q, --quiet                 Give less output. Option is additive, and can be used up
                              to 3 times (corresponding to WARNING, ERROR, and
                              CRITICAL logging levels).
  --log <path>                Path to a verbose appending log.
  --no-input                  Disable prompting for input.
  --proxy <proxy>             Specify a proxy in the form
                              [user:passwd@]proxy.server:port.
  --retries <retries>         Maximum number of retries each connection should attempt
                              (default 5 times).
  --timeout <sec>             Set the socket timeout (default 15 seconds).
  --exists-action <action>    Default action when a path already exists: (s)witch,
                              (i)gnore, (w)ipe, (b)ackup, (a)bort.
  --trusted-host <hostname>   Mark this host or host:port pair as trusted, even though
                              it does not have valid or any HTTPS.
  --cert <path>               Path to PEM-encoded CA certificate bundle. If provided,
                              overrides the default. See 'SSL Certificate
                              Verification' in pip documentation for more information.
  --client-cert <path>        Path to SSL client certificate, a single file containing
                              the private key and the certificate in PEM format.
  --cache-dir <dir>           Store the cache data in <dir>.
  --no-cache-dir              Disable the cache.
  --disable-pip-version-check
                              Don't periodically check PyPI to determine whether a new
                              version of pip is available for download. Implied with
                              --no-index.
  --no-color                  Suppress colored output.
  --no-python-version-warning
                              Silence deprecation warnings for upcoming unsupported
                              Pythons.
  --use-feature <feature>     Enable new functionality, that may be backward
                              incompatible.
  --use-deprecated <feature>  Enable deprecated functionality, that will be removed in
                              the future.

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64

(1)延长timeout时间

因为

--timeout <sec>             Set the socket timeout (default 15 seconds).
  • 1

默认只有15秒,我们可以设置为200

pip3 --default-timeout=200 install "python库名"
  • 1

(2)pip源切换为国内镜像

镜像地址:

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

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

命令如下

pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple "python库名"
# 或者
pip3 install -i http://mirrors.aliyun.com/pypi/simple/ "python库名"
  • 1
  • 2
  • 3

(3)linux上永久切换pip源为国内镜像源

vim ~/.pip/pip.conf
  • 1

显示为:

[list]
format=columns
  • 1
  • 2

插入内容:

[list]
format=columns
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
extra-index-url=http://mirrors.aliyun.com/pypi/simple/
timeout = 200
[install]
trusted-host = https://pypi.tuna.tsinghua.edu.cn
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
参数解释:

在pip --help的结果中,我们看到

pip [options]

command是命令,包括install,download,uninstall等等子命令

options是参数选项,比如-V是查看版本信息,-h是帮助

global: 在[global]下设置的index-url,extra-index-url对command下的命令都生效

install:这个install指的是command下的子命令,我们为这个命令单独配置,就会用到[install]

当需要查看指定命令的参数选项的时候,使用的方法如下:

pip help '命令名'
# 例如
pip help install
  • 1
  • 2
  • 3

(4)windows上永久切换pip源为国内镜像源

用户目录下,如:C:\Users\hjjge\pip\pip.ini
新建pip.ini文件
内容如下:

[list]
format=columns
[global]
index-url=https://pypi.tuna.tsinghua.edu.cn/simple/
extra-index-url=
	https://mirrors.aliyun.com/pypi/simple/
	https://pypi.mirrors.ustc.edu.cn/simple/
	https://pypi.douban.com/simple/
[install]
trusted-host=mirrors.aliyun.com


;[install]
;trusted-host=192.168.206.229
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小桥流水78/article/detail/984189
推荐阅读
相关标签
  

闽ICP备14008679号