pypa / packaging-problems

An issue tracker for the problems in packaging
151 stars 35 forks source link

pip install times out: 'Failed to establish a new connection [Errno 110001]' #695

Open gregparkes opened 1 year ago

gregparkes commented 1 year ago

Problem description

OS version

Windows 11

Python version

3.11

pip version

23.2.1

Problem description

I've installed a fresh version of Anaconda (v23.7.4) and attempted to install some packages using pip and a standard requirements.txt file (numpy first).

Basically, when I run anything to do with pip install, the request times out and does the 5 retries. My suspicion is an SSL certification problem but I'm not sure.

I note that conda installations do work (e.g conda install ...) but there are certain use cases and packages which only pip supply.

Running the following command in Anaconda prompt (within a conda environment):

pip install --upgrade -vvv -r requirements.txt

Gives:

Using pip 23.2.1 from C:\Users\Gregory\anaconda3\envs\mnist-draw\Lib\site-packages\pip (python 3.11)
Non-user install because site-packages writeable
Created temporary directory: C:\Users\Gregory\AppData\Local\Temp\pip-build-tracker-gppopzqv
Initialized build tracking at C:\Users\Gregory\AppData\Local\Temp\pip-build-tracker-gppopzqv
Created build tracker: C:\Users\Gregory\AppData\Local\Temp\pip-build-tracker-gppopzqv
Entered build tracker: C:\Users\Gregory\AppData\Local\Temp\pip-build-tracker-gppopzqv
Created temporary directory: C:\Users\Gregory\AppData\Local\Temp\pip-install-pbtzs_73
Created temporary directory: C:\Users\Gregory\AppData\Local\Temp\pip-ephem-wheel-cache-a54r2fas
1 location(s) to search for versions of numpy:
* https://pypi.org/simple/numpy/
Fetching project page and analyzing links: https://pypi.org/simple/numpy/
Getting page https://pypi.org/simple/numpy/
Found index url https://pypi.org/simple/
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
Incremented Retry for (url='/simple/numpy/'): Retry(total=4, connect=None, read=None, redirect=None, status=None)
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 0x0000026363F1F710>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed')': /simple/numpy/
Starting new HTTPS connection (2): pypi.org:443
Incremented Retry for (url='/simple/numpy/'): Retry(total=3, connect=None, read=None, redirect=None, status=None)
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x0000026363F12790>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed')': /simple/numpy/

I am able to ping the website https://pypi.org/simple in Powershell and access through the browser:

ping www.pypi.org

Pinging dualstack.r.ssl.global.fastly.net [151.101.129.63] with 32 bytes of data:
Reply from 151.101.129.63: bytes=32 time=6ms TTL=57
Reply from 151.101.129.63: bytes=32 time=8ms TTL=57
Reply from 151.101.129.63: bytes=32 time=10ms TTL=57
Reply from 151.101.129.63: bytes=32 time=8ms TTL=57

And when I run pip config debug I get:

env_var:
env:
global:
  C:\ProgramData\pip\pip.ini, exists: True
    index.url: https://pypi.org/simple
site:
  C:\Users\Gregory\anaconda3\envs\mnist-draw\pip.ini, exists: False
user:
  C:\Users\Gregory\pip\pip.ini, exists: False
  C:\Users\Gregory\AppData\Roaming\pip\pip.ini, exists: False

Finally, I attempted to access the packages programmatically using requests:

import requests
response = requests.get("https://pypi.org/simple/")

which yields:

Traceback (most recent call last):
  File "C:\Users\Gregory\anaconda3\envs\mnist-draw\Lib\site-packages\urllib3\connection.py", line 174, in _new_conn
    conn = connection.create_connection(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Gregory\anaconda3\envs\mnist-draw\Lib\site-packages\urllib3\util\connection.py", line 72, in create_connection
    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Gregory\anaconda3\envs\mnist-draw\Lib\socket.py", line 962, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
socket.gaierror: [Errno 11001] getaddrinfo failed

Any help would be greatly appreciated - apologies if this is blindingly obvious.

f-zl commented 9 months ago

Hi, I've met the same problem. Can I know how you solved it?

jeanas commented 9 months ago

Maybe the Windows antivirus is blocking the connection?

f-zl commented 9 months ago

Hi, I've met the same problem. Can I know how you solved it?

I was installing a conda environment in Windows wsl. Network connection was fine but pip install <package> failed with NewConnectionError Failed to establish a new connection: [Errno -2]. Solved by restarting wsl: wsl --shutdown

RomeshA commented 7 months ago

@f-zl Thanks, this resolved the issue for me as well - Windows 11, using WSL1 Ubuntu 22.04 installing Python 3.12 in conda. Pinging websites was fine, my other conda environment with Python 3.11 was also fine. Restarting WSL with wsl --shutdown immediately fixed it for my Python 3.12 environment