pip安装python库出现Read timed out解决办法
问题如下
pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.
解决办法
查看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)延长timeout时间
因为
--timeout <sec> Set the socket timeout (default 15 seconds).
默认只有15秒,我们可以设置为200
pip3 --default-timeout=200 install "python库名"
(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库名"
(3)linux上永久切换pip源为国内镜像源
vim ~/.pip/pip.conf
显示为:
[list]
format=columns
插入内容:
[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
参数解释:
在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
(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