requests.packages.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool[host='files.pythonhosted.org', port=443]: Read timed out.
1. requests.packages.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host=‘files.pythonhosted.org’, port=443): Read timed out.
sudo pip3 install opencv-python==3.4.0.14
guipc@deepnorth01:~/people_counting_api$ sudo pip3 install opencv-python==3.4.0.14
The directory '/home/guipc/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/guipc/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting opencv-python==3.4.0.14
Downloading https://files.pythonhosted.org/packages/8d/12/b4dd4458ac1646278aba8c4ee2e0619796ffd08ed69e8526d6dc34e47242/opencv_python-3.4.0.14-cp35-cp35m-manylinux1_x86_64.whl (24.8MB)
22% |███████▎ | 5.6MB 3.8kB/s eta 1:24:36Exception:
Traceback (most recent call last):
File "/usr/share/python-wheels/urllib3-1.13.1-py2.py3-none-any.whl/urllib3/response.py", line 226, in _error_catcher
yield
File "/usr/share/python-wheels/urllib3-1.13.1-py2.py3-none-any.whl/urllib3/response.py", line 301, in read
data = self._fp.read(amt)
File "/usr/share/python-wheels/CacheControl-0.11.5-py2.py3-none-any.whl/cachecontrol/filewrapper.py", line 49, in read
data = self.__fp.read(amt)
File "/usr/lib/python3.5/http/client.py", line 448, in read
n = self.readinto(b)
File "/usr/lib/python3.5/http/client.py", line 488, in readinto
n = self.fp.readinto(b)
File "/usr/lib/python3.5/socket.py", line 575, in readinto
return self._sock.recv_into(b)
File "/usr/lib/python3.5/ssl.py", line 929, in recv_into
return self.read(nbytes, buffer)
File "/usr/lib/python3.5/ssl.py", line 791, in read
return self._sslobj.read(len, buffer)
File "/usr/lib/python3.5/ssl.py", line 575, in read
v = self._sslobj.read(len, buffer)
socket.timeout: The read operation timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/pip/basecommand.py", line 209, in main
status = self.run(options, args)
File "/usr/lib/python3/dist-packages/pip/commands/install.py", line 317, in run
requirement_set.prepare_files(finder)
File "/usr/lib/python3/dist-packages/pip/req/req_set.py", line 360, in prepare_files
ignore_dependencies=self.ignore_dependencies))
File "/usr/lib/python3/dist-packages/pip/req/req_set.py", line 577, in _prepare_file
session=self.session, hashes=hashes)
File "/usr/lib/python3/dist-packages/pip/download.py", line 810, in unpack_url
hashes=hashes
File "/usr/lib/python3/dist-packages/pip/download.py", line 649, in unpack_http_url
hashes)
File "/usr/lib/python3/dist-packages/pip/download.py", line 871, in _download_http_url
_download_url(resp, link, content_file, hashes)
File "/usr/lib/python3/dist-packages/pip/download.py", line 595, in _download_url
hashes.check_against_chunks(downloaded_chunks)
File "/usr/lib/python3/dist-packages/pip/utils/hashes.py", line 46, in check_against_chunks
for chunk in chunks:
File "/usr/lib/python3/dist-packages/pip/download.py", line 563, in written_chunks
for chunk in chunks:
File "/usr/lib/python3/dist-packages/pip/utils/ui.py", line 139, in iter
for x in it:
File "/usr/lib/python3/dist-packages/pip/download.py", line 552, in resp_read
decode_content=False):
File "/usr/share/python-wheels/urllib3-1.13.1-py2.py3-none-any.whl/urllib3/response.py", line 344, in stream
data = self.read(amt=amt, decode_content=decode_content)
File "/usr/share/python-wheels/urllib3-1.13.1-py2.py3-none-any.whl/urllib3/response.py", line 311, in read
flush_decoder = True
File "/usr/lib/python3.5/contextlib.py", line 77, in __exit__
self.gen.throw(type, value, traceback)
File "/usr/share/python-wheels/urllib3-1.13.1-py2.py3-none-any.whl/urllib3/response.py", line 231, in _error_catcher
raise ReadTimeoutError(self._pool, None, 'Read timed out.')
requests.packages.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.
guipc@deepnorth01:~/people_counting_api$
2. pip install 安装软件包失败的解决方案
网络原因导致安装超时,需要重新下载安装。
2.1. 延长超时时间
--timeout <sec>
(base) yongqiang@yongqiang:~$ pip --help
General Options:
-h, --help Show help.
-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).
--retries <retries> Maximum number of retries each connection should attempt (default 5 times).
--timeout <sec> Set the socket timeout (default 15 seconds).
...
--default-timeout=<sec>
https://readdoctest.readthedocs.io/en/latest/user_guide.html
pip’s command line options can be set with environment variables using the format PIP_<UPPER_LONG_NAME>
. Dashes (-
) have to be replaced with underscores (_
).
For example, to set the default timeout:
export PIP_DEFAULT_TIMEOUT=60
This is the same as passing the option to pip directly:
pip --default-timeout=60 [...]
下载命令后添加参数 --default-timeout=1000
,时间可以自定义。
pip install 默认超时时间是 15s,在安装的过程中可能会超时。我们在执行命令时,可显式设置超时时间。
--default-timeout=100
--default-timeout=500
--default-timeout=1000
For instance,
sudo pip3 --default-timeout=100 install opencv-python==3.4.0.14
sudo pip3 --default-timeout=1000 install opencv-python==3.4.0.14
guipc@deepnorth01:~/people_counting_api$ sudo pip3 --default-timeout=1000 install opencv-python==3.4.0.14
[sudo] password for guipc:
The directory '/home/guipc/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/guipc/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting opencv-python==3.4.0.14
Downloading https://files.pythonhosted.org/packages/8d/12/b4dd4458ac1646278aba8c4ee2e0619796ffd08ed69e8526d6dc34e47242/opencv_python-3.4.0.14-cp35-cp35m-manylinux1_x86_64.whl (24.8MB)
100% |████████████████████████████████| 24.8MB 10kB/s
Collecting numpy>=1.11.1 (from opencv-python==3.4.0.14)
Downloading https://files.pythonhosted.org/packages/d4/64/7619774f0bd8ef364d46a5df8eb1bc78784cd787324b9624f6793e72f787/numpy-1.17.1-cp35-cp35m-manylinux1_x86_64.whl (20.1MB)
100% |████████████████████████████████| 20.2MB 14kB/s
Installing collected packages: numpy, opencv-python
Found existing installation: numpy 1.11.0
Not uninstalling numpy at /usr/lib/python3/dist-packages, outside environment /usr
Successfully installed numpy-1.17.1 opencv-python-3.4.0.14
You are using pip version 8.1.1, however version 19.2.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
guipc@deepnorth01:~/people_counting_api$
2.2. 更换 PyPI (pip) 镜像源
- 临时使用
使用 pip 的时候在后面加上 -i
参数,指定 pip 源:
pip install -i https://mirrors.zju.edu.cn/pypi/web/simple some-package
pip install -i https://mirrors.ustc.edu.cn/pypi/web/simple some-package
其中 simple
不能少,若使用 http
镜像需要加上 --trusted-host mirrors.zju.edu.cn
- 设为默认
升级 pip 到最新的版本 (>=10.0.0) 后进行配置:
pip install pip -U
pip config set global.index-url https://mirrors.zju.edu.cn/pypi/web/simple
如果你到 pip 默认源的网络连接较差,临时使用本镜像站来升级 pip:
pip install -i https://mirrors.zju.edu.cn/pypi/web/simple pip -U
pip config set global.index-url https://mirrors.zju.edu.cn/pypi/web/simple
pip install -i https://mirrors.ustc.edu.cn/pypi/web/simple pip -U
pip config set global.index-url https://mirrors.ustc.edu.cn/pypi/web/simple
For instance,
sudo pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple scipy
sudo pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple scikit-learn
guipc@deepnorth01:~/people_counting_api$ sudo pip3 install -i https://pypi.douban.com/simple scipy
[sudo] password for guipc:
The directory '/home/guipc/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owne r of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/guipc/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of th at directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting scipy
Downloading https://pypi.doubanio.com/packages/7a/0e/3781e028d62a8422244582abd8f084e6314297026760587c85607f687bf3/scipy-1.3.1-cp35-cp35m-manylinux1_x86_64.whl (25.1MB)
100% |████████████████████████████████| 25.1MB 61kB/s
Requirement already satisfied (use --upgrade to upgrade): numpy>=1.13.3 in /usr/local/lib/python3.5/dist-packages (from scipy)
Installing collected packages: scipy
Successfully installed scipy-1.3.1
You are using pip version 8.1.1, however version 19.2.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
guipc@deepnorth01:~/people_counting_api$
guipc@deepnorth01:~/people_counting_api$ sudo pip3 install -i https://pypi.douban.com/simple scikit-learn
The directory '/home/guipc/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owne r of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/guipc/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of th at directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting scikit-learn
Downloading https://pypi.doubanio.com/packages/1f/af/e3c3cd6f61093830059138624dbd26d938d6da1caeec5aeabe772b916069/scikit_learn-0.21.3-cp35-cp35m-manylinux1_x86_64.whl (6 .6MB)
100% |████████████████████████████████| 6.6MB 224kB/s
Requirement already satisfied (use --upgrade to upgrade): numpy>=1.11.0 in /usr/local/lib/python3.5/dist-packages (from scikit-learn)
Collecting joblib>=0.11 (from scikit-learn)
Downloading https://pypi.doubanio.com/packages/cd/c1/50a758e8247561e58cb87305b1e90b171b8c767b15b12a1734001f41d356/joblib-0.13.2-py2.py3-none-any.whl (278kB)
100% |████████████████████████████████| 286kB 6.2MB/s
Requirement already satisfied (use --upgrade to upgrade): scipy>=0.17.0 in /usr/local/lib/python3.5/dist-packages (from scikit-learn)
Installing collected packages: joblib, scikit-learn
Successfully installed joblib-0.13.2 scikit-learn-0.21.3
You are using pip version 8.1.1, however version 19.2.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
guipc@deepnorth01:~/people_counting_api$
2.3. PyPI (pip) 镜像源
- 清华大学开源软件镜像站
https://mirrors.tuna.tsinghua.edu.cn/
https://pypi.tuna.tsinghua.edu.cn/simple
sudo pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple scipy
sudo pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple scikit-learn
- 阿里巴巴 OPSX 开源镜像站
https://developer.aliyun.com/mirror/
https://mirrors.aliyun.com/pypi/simple
sudo pip3 install -i https://mirrors.aliyun.com/pypi/simple scipy
sudo pip3 install -i https://mirrors.aliyun.com/pypi/simple scikit-learn
https://mirrors.cloud.tencent.com/pypi/simple/
sudo pip3 install -i https://mirrors.cloud.tencent.com/pypi/simple scipy
sudo pip3 install -i https://mirrors.cloud.tencent.com/pypi/simple scikit-learn
- 中国科学技术大学开源软件镜像 (USTC open source software mirror)
https://mirrors.ustc.edu.cn/
https://mirrors.ustc.edu.cn/help/pypi.html
https://mirrors.ustc.edu.cn/pypi/web/simple
sudo pip3 install -i https://mirrors.ustc.edu.cn/pypi/web/simple scipy
sudo pip3 install -i https://mirrors.ustc.edu.cn/pypi/web/simple scikit-learn
同步方式:使用 bandersnatch,从 pypi.python.org 官方同步。
- 北京外国语大学开源软件镜像站
https://mirrors.bfsu.edu.cn/
https://mirrors.bfsu.edu.cn/pypi/web/simple
sudo pip3 install -i https://mirrors.bfsu.edu.cn/pypi/web/simple scipy
sudo pip3 install -i https://mirrors.bfsu.edu.cn/pypi/web/simple scikit-learn
- 北京大学开源镜像站
https://mirrors.pku.edu.cn/Mirrors
https://mirrors.pku.edu.cn/pypi/web/simple
sudo pip3 install -i https://mirrors.pku.edu.cn/pypi/web/simple scipy
sudo pip3 install -i https://mirrors.pku.edu.cn/pypi/web/simple scikit-learn
- SJTUG (上海交通大学 Linux 用户组) 软件源镜像服务
https://mirrors.sjtug.sjtu.edu.cn/
https://mirror.sjtu.edu.cn/pypi/web/simple
sudo pip3 install -i https://mirror.sjtu.edu.cn/pypi/web/simple scipy
sudo pip3 install -i https://mirror.sjtu.edu.cn/pypi/web/simple scikit-learn
https://mirrors.zju.edu.cn/pypi/web/simple
sudo pip3 install -i https://mirrors.zju.edu.cn/pypi/web/simple scipy
sudo pip3 install -i https://mirrors.zju.edu.cn/pypi/web/simple scikit-learn
- 网易开源镜像站
http://mirrors.163.com/
pypi 镜像使用帮助
http://mirrors.163.com/.help/pypi.html
https://mirrors.163.com/pypi/simple/
pip install xxx -i https://mirrors.163.com/pypi/simple/
sudo pip3 install -i https://mirrors.163.com/pypi/simple/ scipy
sudo pip3 install -i https://mirrors.163.com/pypi/simple/ scikit-learn
3. Installing from Wheels
“Wheel” is a built, archive format that can greatly speed installation compared to building and installing from source archives.
User Guide
https://pip.pypa.io/en/latest/user_guide/
Wheel Docs
https://wheel.readthedocs.io/en/stable/
PEP 427 – The Wheel Binary Package Format 1.0
https://peps.python.org/pep-0427/
PEP 425 – Compatibility Tags for Built Distributions
https://peps.python.org/pep-0425/
下载离线安装包,使用 pip install ******.whl
安装。
- https://pypi.tuna.tsinghua.edu.cn/simple/
查找 nn-meter 文件夹。
- https://pypi.tuna.tsinghua.edu.cn/simple/nn-meter/
- To install a wheel file, use pip:
$ pip install someproject-1.5.0-py2-py3-none.whl
$ python -m pip install SomePackage-1.0-py2.py3-none-any.whl
References
[1] Yongqiang Cheng, https://yongqiang.blog.csdn.net/
[2] pip, https://pip.pypa.io/en/stable/
[3] USTC Mirror Help, https://mirrors.ustc.edu.cn/help/index.html
[4] PyPI 镜像源使用帮助,https://mirrors.ustc.edu.cn/help/pypi.html
[5] User Guide, https://pip.pypa.io/en/latest/user_guide/
[6] bandersnatch, https://pypi.org/project/bandersnatch/