Build fails - presumably on a slow connection

Not really a question here, just an FYI for anyone working on a local machine, with a slow(ish) connection. The build may fail with some spectacular error messaging (example 2 below). The solution might be to set the timeout during the pip install (example 1 below).
Still got some warnings with this command, but this built for me eventually. My env; Ubuntu Server 20.04 VM.

1) Updated pip install

RUN pip3 install --upgrade pip; \
    pip3 install --default-timeout=100 "ansible==2.9.12"

2) Original error message

Collecting ansible==2.9.12
  Downloading ansible-2.9.12.tar.gz (14.3 MB)
ERROR: Exception:
Traceback (most recent call last):
  File "/usr/share/python-wheels/urllib3-1.25.8-py2.py3-none-any.whl/urllib3/", line 425, in _error_catcher
  File "/usr/share/python-wheels/urllib3-1.25.8-py2.py3-none-any.whl/urllib3/", line 507, in read
    data = if not fp_closed else b""
  File "/usr/share/python-wheels/CacheControl-0.12.6-py2.py3-none-any.whl/cachecontrol/", line 62, in read
    data =
  File "/usr/lib/python3.8/http/", line 459, in read
    n = self.readinto(b)
  File "/usr/lib/python3.8/http/", line 503, in readinto
    n = self.fp.readinto(b)
  File "/usr/lib/python3.8/", line 669, in readinto
    return self._sock.recv_into(b)
  File "/usr/lib/python3.8/", line 1241, in recv_into
    return, buffer)
  File "/usr/lib/python3.8/", line 1099, in read
    return, 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/_internal/cli/", line 186, in _main
    status =, args)
  File "/usr/lib/python3/dist-packages/pip/_internal/commands/", line 357, in run
  File "/usr/lib/python3/dist-packages/pip/_internal/", line 177, in resolve
    discovered_reqs.extend(self._resolve_one(requirement_set, req))
  File "/usr/lib/python3/dist-packages/pip/_internal/", line 333, in _resolve_one
    abstract_dist = self._get_abstract_dist_for(req_to_install)
  File "/usr/lib/python3/dist-packages/pip/_internal/", line 282, in _get_abstract_dist_for
    abstract_dist = self.preparer.prepare_linked_requirement(req)
  File "/usr/lib/python3/dist-packages/pip/_internal/operations/", line 480, in prepare_linked_requirement
    local_path = unpack_url(
  File "/usr/lib/python3/dist-packages/pip/_internal/operations/", line 282, in unpack_url
    return unpack_http_url(
  File "/usr/lib/python3/dist-packages/pip/_internal/operations/", line 158, in unpack_http_url
    from_path, content_type = _download_http_url(
  File "/usr/lib/python3/dist-packages/pip/_internal/operations/", line 303, in _download_http_url
    for chunk in download.chunks:
  File "/usr/lib/python3/dist-packages/pip/_internal/utils/", line 160, in iter
    for x in it:
  File "/usr/lib/python3/dist-packages/pip/_internal/network/", line 15, in response_chunks
    for chunk in
  File "/usr/share/python-wheels/urllib3-1.25.8-py2.py3-none-any.whl/urllib3/", line 564, in stream
    data =, decode_content=decode_content)
  File "/usr/share/python-wheels/urllib3-1.25.8-py2.py3-none-any.whl/urllib3/", line 529, in read
    raise IncompleteRead(self._fp_bytes_read, self.length_remaining)
  File "/usr/lib/python3.8/", line 131, in __exit__
    self.gen.throw(type, value, traceback)
  File "/usr/share/python-wheels/urllib3-1.25.8-py2.py3-none-any.whl/urllib3/", line 430, in _error_catcher
    raise ReadTimeoutError(self._pool, None, "Read timed out.")
urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='', port=443): Read timed out.

can you please run this command and then upgrade pip.

sudo apt install python3-venv
python -m venv dirname
source dirname/bin/activate

Thanks for the suggestion. Not sure what this is supposed to achieve though. The above happens when building a container, so installing python3-venv seems somewhat besides the point to me.
I found a solution anyway (given in question).