Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error "socket.timeout: The read operation timed out" while installing a python module

Tags:

python

pip

spacy

I was triying to install the large English module "en_core_web_lg" for spaCy (a library for Natural Language Processing)

For some reasons, the small and medium modules were successfully installed (with few errors at first), but the large module always crashed installation.

I have used two different methods:

1)

$ python -m spacy download en_core_web_lg

2)

$ pip install https://github.com/explosion/spacy-models/releases/download/en_core_web_lg-2.0.0/en_core_web_lg-2.0.0.tar.gz

But in both cases I always got these two Exceptions:

(venv) omar@omar-device:~/virtualenvironment/my_new_app/bin/venv/bin$ pip3 install https://github.com/explosion/spacy-models/releases/download/en_core_web_lg-2.0.0/en_core_web_lg-2.0.0.tar.gz
Collecting https://github.com/explosion/spacy-models/releases/download/en_core_web_lg-2.0.0/en_core_web_lg-2.0.0.tar.gz
  Downloading https://github.com/explosion/spacy-models/releases/download/en_core_web_lg-2.0.0/en_core_web_lg-2.0.0.tar.gz (852.3MB)
    38% |████████████▎                   | 325.7MB 114kB/s eta 1:16:26Exception:
Traceback (most recent call last):
  File "/home/omar/virtualenvironment/my_new_app/bin/venv/lib/python3.5/site-packages/pip/_vendor/urllib3/response.py", line 331, in _error_catcher
    yield
  File "/home/omar/virtualenvironment/my_new_app/bin/venv/lib/python3.5/site-packages/pip/_vendor/urllib3/response.py", line 413, in read
    data = self._fp.read(amt)
  File "/home/omar/virtualenvironment/my_new_app/bin/venv/lib/python3.5/site-packages/pip/_vendor/cachecontrol/filewrapper.py", line 62, 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 "/home/omar/virtualenvironment/my_new_app/bin/venv/lib/python3.5/site-packages/pip/_internal/basecommand.py", line 141, in main
    status = self.run(options, args)
  File "/home/omar/virtualenvironment/my_new_app/bin/venv/lib/python3.5/site-packages/pip/_internal/commands/install.py", line 299, in run
    resolver.resolve(requirement_set)
  File "/home/omar/virtualenvironment/my_new_app/bin/venv/lib/python3.5/site-packages/pip/_internal/resolve.py", line 102, in resolve
    self._resolve_one(requirement_set, req)
  File "/home/omar/virtualenvironment/my_new_app/bin/venv/lib/python3.5/site-packages/pip/_internal/resolve.py", line 256, in _resolve_one
    abstract_dist = self._get_abstract_dist_for(req_to_install)
  File "/home/omar/virtualenvironment/my_new_app/bin/venv/lib/python3.5/site-packages/pip/_internal/resolve.py", line 209, in _get_abstract_dist_for
    self.require_hashes
  File "/home/omar/virtualenvironment/my_new_app/bin/venv/lib/python3.5/site-packages/pip/_internal/operations/prepare.py", line 283, in prepare_linked_requirement
    progress_bar=self.progress_bar
  File "/home/omar/virtualenvironment/my_new_app/bin/venv/lib/python3.5/site-packages/pip/_internal/download.py", line 836, in unpack_url
    progress_bar=progress_bar
  File "/home/omar/virtualenvironment/my_new_app/bin/venv/lib/python3.5/site-packages/pip/_internal/download.py", line 673, in unpack_http_url
    progress_bar)
  File "/home/omar/virtualenvironment/my_new_app/bin/venv/lib/python3.5/site-packages/pip/_internal/download.py", line 897, in _download_http_url
    _download_url(resp, link, content_file, hashes, progress_bar)
  File "/home/omar/virtualenvironment/my_new_app/bin/venv/lib/python3.5/site-packages/pip/_internal/download.py", line 619, in _download_url
    consume(downloaded_chunks)
  File "/home/omar/virtualenvironment/my_new_app/bin/venv/lib/python3.5/site-packages/pip/_internal/utils/misc.py", line 844, in consume
    deque(iterator, maxlen=0)
  File "/home/omar/virtualenvironment/my_new_app/bin/venv/lib/python3.5/site-packages/pip/_internal/download.py", line 585, in written_chunks
    for chunk in chunks:
  File "/home/omar/virtualenvironment/my_new_app/bin/venv/lib/python3.5/site-packages/pip/_internal/utils/ui.py", line 159, in iter
    for x in it:
  File "/home/omar/virtualenvironment/my_new_app/bin/venv/lib/python3.5/site-packages/pip/_internal/download.py", line 574, in resp_read
    decode_content=False):
  File "/home/omar/virtualenvironment/my_new_app/bin/venv/lib/python3.5/site-packages/pip/_vendor/urllib3/response.py", line 465, in stream
    data = self.read(amt=amt, decode_content=decode_content)
  File "/home/omar/virtualenvironment/my_new_app/bin/venv/lib/python3.5/site-packages/pip/_vendor/urllib3/response.py", line 430, in read
    raise IncompleteRead(self._fp_bytes_read, self.length_remaining)
  File "/usr/lib/python3.5/contextlib.py", line 77, in __exit__
    self.gen.throw(type, value, traceback)
  File "/home/omar/virtualenvironment/my_new_app/bin/venv/lib/python3.5/site-packages/pip/_vendor/urllib3/response.py", line 336, in _error_catcher
    raise ReadTimeoutError(self._pool, None, 'Read timed out.')
pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='github-production-release-asset-2e65be.s3.amazonaws.com', port=443): Read timed out.

I tried to reinstall Python3 at first, but crashed my desktop and terminal and had to fix that using the console :D (using this answer https://askubuntu.com/questions/384033/removed-python-3-and-now-ubuntu-software-center-terminal-and-other-applications).

like image 214
Omar Avatar asked Jul 26 '18 15:07

Omar


People also ask

What is socket timeout Python?

Socket connection timeout High A new Python socket by default doesn't have a timeout. Its timeout defaults to None. Not setting the connection timeout parameter can result in blocking socket mode. In blocking mode, operations block until complete or the system returns an error.

What is socket timeout error?

TCP Socket Timeouts are caused when a TCP socket times out talking to the far end. Socket timeouts can occur when attempting to connect to a remote server, or during communication, especially long-lived ones.

How to fix pip install read timeout error in Python?

As a python programmer, we often use pip intall command to install python libary. However, we often encounter read timeout error when installing. In this tutorial, we will introduce a new way to fix this read timeout error. To fix pip install read timeout error, we have two ways: Method 1: Set a long read time and retry times for pip

How to fix a connection timeout error in Python?

The connect () operation is also subject to the timeout setting, and in general it is recommended to call settimeout () before calling connect () or pass a timeout parameter to create_connection (). However, the system network stack may also return a connection timeout error of its own regardless of any Python socket timeout setting.

How do I set socket timeout in Python?

Fortunately, Python gives you a chance to set up socket timeout for all new sockets, which will be created during application work: import socket socket.setdefaulttimeout (10) sock = socket.socket ()

How to catch SSL timeout error in Python 2?

In Python 2 we have # to specifically catch it and throw the timeout error if hasattr(err, 'errno') and err.errno in _blocking_errnos: raise ReadTimeoutError(self, url, "Read timed out. (read timeout=%s)" % timeout_value) # Catch possible read timeouts thrown as SSL errors. If not the # case, rethrow the original.


Video Answer


1 Answers

try increasing pip timeout: pip install --default-timeout=900 [pkg_name]

like image 124
ekeyser Avatar answered Oct 06 '22 23:10

ekeyser