Search code examples
pythonpippython-requestsgoogle-compute-enginegoogle-cloud-networking

pip install failing with NewConnectionError on debian


I often do pip install <package-name> on my Google Compute Engine (Debian) within the virtual environment but today I am just getting the new connection error for any package that I try to install:

 Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) 
    after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7f42a65bdf60>: 
    Failed to establish a new connection: [Errno 101] Network is unreachable',)': 
    /packages/49/df/50aa1999ab9bde74656c2919d9c0c085fd2b3775fd3eca826012bef76d8c/requests-2.18.4-py2.py3-none-any.whl

I know there are other related posts that suggest specifying a proxy but I have been pip install ing many times in the past on the same machine but somehow its just returning the above error today. Doesn't really look like a proxy issue. What could have changed?

pip version is 10.0.1 and the machine obviously has live internet connection (its our prod server on Google Compute Engine). I can successfully ping websites from the machine.


Solution

  • Need to open port 443 for outgoing traffic (to specific IP(s)) on Google Compute Engine instance since pip3 runs over HTTPS.

    Refer to GCP docs for detailed instructions on how to do it (using command line or the GUI). Get the IP of files.pythonhosted.org to set the destination IP.

    (This helpful comment points out the same issue with using pip3 on an AWS EC2 instance)