Search code examples
pythonpython-3.xpip

pip WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) error


I faced error which is pip can't download packages

the error is


ERROR: Could not install packages due to an OSError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Max retries exceeded with url: /packages/f5/11/fc3de994aa4648632f3512ca18686fb82e6f250d82dda544a09f96726dae/pipenv-2023.11.15-py3-none-any.whl.metadata (Caused by NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f23739c9d60>: Failed to establish a new connection: [Errno 101] Network is unreachable'))

My ubuntu version 18.04.1 and 20.04.4

python version 3.8 / 3.12

pip version 23.3.1

after I changed python version using

sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.8

below error happen when I use pip install

Defaulting to user installation because normal site-packages is not writeable
Collecting pip
  WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f7b37313f40>: Failed to establish a new connection: [Errno 101] Network is unreachable')': 

before I changed python(python3.6) pip worked well

I saw many people have this problem and solved but even I tried every things in internet I counldn't solve this

What I tried

  1. I tried internet connection
ping google.com
ping pypi.org
etc ....

---

result is 


PING pypi.org (151.101.64.223) 56(84) bytes of data.
64 bytes from 151.101.64.223 (151.101.64.223): icmp_seq=1 ttl=54 time=6.10 ms
64 bytes from 151.101.64.223 (151.101.64.223): icmp_seq=2 ttl=54 time=6.12 ms
64 bytes from 151.101.64.223 (151.101.64.223): icmp_seq=3 ttl=54 time=6.09 ms
64 bytes from 151.101.64.223 (151.101.64.223): icmp_seq=4 ttl=54 time=6.14 ms
64 bytes from 151.101.64.223 (151.101.64.223): icmp_seq=5 ttl=54 time=6.11 ms
64 bytes from 151.101.64.223 (151.101.64.223): icmp_seq=6 ttl=54 time=6.09 ms
^C
--- pypi.org ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 5008ms

  1. I reinstalled pip and python and apt-get update, changing to python2, remove alternatives about python

  2. remove Anaconda python

  3. use ln -s /usr/bin/python3 /usr/bin/python3.8

  4. install another version of python 7,8,9,10,11 etc

  5. check curl working (i.e curl https://pypi.org/simple/flask-bcrypt/)

  6. pip install --upgrade pip --trusted-host pypi.org --trusted-host files.pythonhosted.org


Solution

  • I solved problem.

    the reason was DNS problem....

    I used 8.8.8.8 google. but it had problem so I changed DNS server and now works well.