Pip hangs on "collecting numpy"

11,563

Solution 1

I had the same issue with Django.

The diff in the output of both commands is the following:

pip install Django -vvv
...
Looking up "https://pypi.org/simple/django/" in the cache
Request header has "max_age" as 0, cache bypassed
https://pypi.org:443 "GET /simple/django/ HTTP/1.1" 304 0
<hangs here>

$ pip install Django --no-cache-dir -vvv
...
https://pypi.org:443 "GET /simple/django/ HTTP/1.1" 200 27460
<continues and successfully installs>

Using --no-cache-dir just bypasses the problem.

The solution came when I manually deleted the contents of the cache directory.

rm -Rf ~/.cache/pip/* allowed pip install Django to work as expected, and the cache started rebuilding itself again.

From the docs you can find the path where the cache lives, based on your os:

The default location for the cache directory depends on the Operating System:

Unix

~/.cache/pip and it respects the XDG_CACHE_HOME directory.

macOS

~/Library/Caches/pip.

Windows

<CSIDL_LOCAL_APPDATA>\pip\Cache

Solution 2

IPv6 somehow caused this problem for me. After disabling ipv6 networking on my device, the command went through fine!

Solution 3

Yo can try adding:

--no-cache-dir

By default, when making any HTTP request pip will first check its local cache to determine if it has a suitable response stored for that request which has not expired. If the error comes in that part of the process, skipping that cache check should fix the problem.

Details in the official pip documentation.

Solution 4

As a workaround, you could manually download and install numpy

Go to here and choose the .whl file of the version you'd like installed: https://pypi.org/simple/numpy/

Once it's downloaded you can manually install the .whl:

pip install numpy-1.16.1-cp37-cp37m-win_amd64.whl

Share:
11,563

Related videos on Youtube

Moseleyi
Author by

Moseleyi

Interested in SQL, MySQL, PostgreSQL STATA, R Social Sciences, Data Collection &amp; Analysis for NGO Sector Monitoring &amp; Evaluation, Partner Assessments Google Sheets &amp; Microsoft Excel Salesforce (including Administration, Data Migration) Database administration

Updated on June 28, 2022

Comments

  • Moseleyi
    Moseleyi almost 2 years

    Trying to install packages for python in Windows 10 machine and python 3.7.2. I'm using the following command:

    pip install numpy
    

    And it hangs forever. I tried to get more information using the following:

    pip -vvv install numpy
    

    and here's the result:

    Collecting numpy
      1 location(s) to search for versions of numpy:
      * https://pypi.org/simple/numpy/
      Getting page https://pypi.org/simple/numpy/
      Looking up "https://pypi.org/simple/numpy/" in the cache
      Request header has "max_age" as 0, cache bypassed
      Starting new HTTPS connection (1): pypi.org:443
      https://pypi.org:443 "GET /simple/numpy/ HTTP/1.1" 304 0
    

    I tried to research it but can't find anything. I can't believe only this package would go through HTTPS and that's why it's failing?

  • Moseleyi
    Moseleyi over 5 years
    Can you elaborate why it would make a difference?
  • Alex Yu
    Alex Yu over 5 years
    Http 304 means "Not Modified". I did not look into source of pip but it's possible that package in cache prevents installation
  • Moseleyi
    Moseleyi over 5 years
    It worked but it wouldn't work with a file of packages to install. For example this: pip install -r req.txt had package pandas which has numpy as dependency. Adding --no-cache-dir didnt' work there and it still hung but it worked when I install numpy on its own
  • Moseleyi
    Moseleyi about 5 years
    That's true, it just bypasses the problem. I still haven't found a long-term solution
  • raratiru
    raratiru about 5 years
    @Moseleyi In my case, when I deleted the cache rm -Rf ~/.cache/pip/*, pip install Django started working without --no-cache-dir and the cache started to rebuild again.
  • Moseleyi
    Moseleyi about 5 years
    hm but how can this be automated? We have a text file called requirements with list of packages to install. I'm not sure I can incpororate this in such script?
  • raratiru
    raratiru about 5 years
    @Moseleyi Oh, no, I did it once manually. When the contents of the cache were removed along with the content that caused pip to freeze hanging unable to do anything, pip install -r requirements.txt is "forever" working as expected without modifications, without --no-cache-dir.
  • raratiru
    raratiru about 5 years
    @Moseleyi There are also posts 1 2 in pip issues and SO implying that is safe to delete the cache.
  • Moseleyi
    Moseleyi about 5 years
    It worked, I deleted the folder and everything went smoothly. Needed to install some C++ Compiler and that's it. Then added everything to the Path and finally it worked! :D