190

I recently need to install some packages

pip install future
pip install scikit-learn
pip install numpy
pip install scipy

I also tried by writin sudo before them but all it came up with the following errors in red lines:

Exception:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 122, in main
    status = self.run(options, args)
  File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 290, in run
    requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
  File "/usr/lib/python2.7/dist-packages/pip/req.py", line 1198, in prepare_files
    do_download,
  File "/usr/lib/python2.7/dist-packages/pip/req.py", line 1376, in unpack_url
    self.session,
  File "/usr/lib/python2.7/dist-packages/pip/download.py", line 572, in unpack_http_url
    download_hash = _download_url(resp, link, temp_location)
  File "/usr/lib/python2.7/dist-packages/pip/download.py", line 433, in _download_url
    for chunk in resp_read(4096):
  File "/usr/lib/python2.7/dist-packages/pip/download.py", line 421, in resp_read
    chunk_size, decode_content=False):
  File "/usr/lib/python2.7/dist-packages/urllib3/response.py", line 256, in stream
    data = self.read(amt=amt, decode_content=decode_content)
  File "/usr/lib/python2.7/dist-packages/urllib3/response.py", line 201, in read
    raise ReadTimeoutError(self._pool, None, 'Read timed out.')
ReadTimeoutError: HTTPSConnectionPool(host='pypi.python.org', port=443): Read timed out.

Storing debug log for failure in /root/.pip/pip.log'
cs95
  • 379,657
  • 97
  • 704
  • 746
Ateeb
  • 5,413
  • 3
  • 10
  • 17
  • 4
    I think it's network problem try `ping pypi.python.org` see if it works. It can be solved with something as simple as restarting your router or reconnecting to your internet or even just trying again after sometime. please follow [How to ask](https://stackoverflow.com/help/how-to-ask) before posting here. – Krishna Chaitanya Kornepati Apr 08 '17 at 18:39
  • 1
    Avoid blindly using sudo to try magically try fix things when you aren't sure it's a permissions issue. It rarely will make things just work, but can mess up your permissions, which can cause you very annoying future issues. Only use sudo when you know it's needed. – aggregate1166877 Mar 16 '23 at 13:00

8 Answers8

330

Use --default-timeout=100 parameter with the install:

sudo pip install --default-timeout=100 future
pkamb
  • 33,281
  • 23
  • 160
  • 191
Ateeb
  • 5,413
  • 3
  • 10
  • 17
  • 34
    Alternatively, I used `export PIP_DEFAULT_TIMEOUT=100` since I had the `pip` command in a shared Dockerfile and it was a temporary requirement for me. But it works, thanks! – Kerem Nov 15 '17 at 12:15
  • 10
    Thanks, It saves me in slow internet condition. I guess 100 is the the number of seconds pip'll wait for the reconnect after losing connection? – Khanh Le Nov 17 '17 at 07:15
  • 1
    Can I make the timeout setting permament? – Timo Mar 30 '18 at 08:05
  • 1
    I cannot find the setting with `pip help` or `pip install help`. There is howerver `socket timeout`. I wonder what is the default value? – Timo Mar 30 '18 at 08:10
  • 1
    I cannot find the setting with `pip help` or `pip install help`. There is howerver `socket timeout`. I wonder what is the default value? – Timo Mar 30 '18 at 08:10
  • 1
    @Timo, use @Kerem's command (`export PIP_DEFAULT_TIMEOUT=100`) in your `~/.profile` to make it permanent. – Chinoto Vokro Jun 29 '20 at 20:56
  • 1
    As per [this comment](https://stackoverflow.com/questions/50305112/pip-install-timeout-issue#comment117142274_61472212) by [asmaier](https://stackoverflow.com/users/179014/asmaier) on [Pip Install Timeout Issue](https://stackoverflow.com/q/50305112/1364007), the parameter may be `--timeout` rather than `--default-timeout`. – Wai Ha Lee Jan 13 '22 at 07:48
  • Another thing you can do in Docker is something like: `RUN python3 -m pip install --default-timeout=100 -r /requirements.txt`. – Arka Mukherjee Jul 02 '22 at 17:39
37
sudo pip install --default-timeout=100 future 

or alternatively

export PIP_DEFAULT_TIMEOUT=100

worked for me on Mac OS X

pkamb
  • 33,281
  • 23
  • 160
  • 191
Jagdish
  • 542
  • 4
  • 9
7

They are two ways to handle this issue:

sudo pip install --default-timeout=100 future

or

pip install --default-timeout=100 future

Note: If you are not superuser of your machine, the sudo pip command will not work.

pkamb
  • 33,281
  • 23
  • 160
  • 191
ARB
  • 319
  • 3
  • 6
1

Upgrading pip solved the problem for me.

python -m pip install --upgrade pip
Bálint Sass
  • 310
  • 3
  • 11
1

Change the value of PIP_DEFAULT_TIMEOUT (the value is an integer in seconds).

set PIP_DEFAULT_TIMEOUT=1200
Majo_Jose
  • 744
  • 1
  • 10
  • 24
0

If you are using JetBrains PyCharm, the appropriate solution steps are :

  1. connect to terminal/open terminal in PyCharm.

  2. type source <path to your projects environment eg: /users/name/myapp/venv>

  3. Run pip install <package name> or run pip3 install <package name> as per your installation

This will automatically install package for your interpreter.

Kins
  • 547
  • 1
  • 5
  • 22
vegetarianCoder
  • 2,762
  • 2
  • 16
  • 27
0

Just throwing this out there to avoid any confusion, for pip3 you can use

sudo pip3 install --default-timeout=100 future
Aniruddha J
  • 385
  • 4
  • 11
0

My problem was that pip couldn't load a specific version of a package, which lead to the same error message i.e. ReadTimeoutError. Try to find the failing package and update it to the latest version.