51

I've Python 3 running in a linux server. I need to install some libraries (obviously) so I'm trying :

pip3 install numpy

Which, is resulting in the following error:

Collecting numpy
  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f7542572828>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /simple/numpy/
  Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f7542572eb8>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /simple/numpy/
  Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f7542572be0>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /simple/numpy/
  Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f7542572d30>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /simple/numpy/
  Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f7542572860>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /simple/numpy/
  Could not find a version that satisfies the requirement numpy (from versions: )
No matching distribution found for numpy

Questions:

  1. What could be the problem? Why is this error being raised?
  2. How can this be avoided in the future?

Feel free to ask for more details.

UPDATE: I tried ping google.com and got the error:

ping: google.com: Name or service not known

But when I tried ping 8.8.8.8, I got:

PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=118 time=10.8 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=118 time=10.6 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=118 time=10.6 ms
64 bytes from 8.8.8.8: icmp_seq=4 ttl=118 time=10.7 ms
64 bytes from 8.8.8.8: icmp_seq=5 ttl=118 time=10.6 ms
64 bytes from 8.8.8.8: icmp_seq=6 ttl=118 time=10.7 ms
64 bytes from 8.8.8.8: icmp_seq=7 ttl=118 time=10.7 ms
64 bytes from 8.8.8.8: icmp_seq=8 ttl=118 time=10.7 ms
64 bytes from 8.8.8.8: icmp_seq=9 ttl=118 time=10.7 ms
64 bytes from 8.8.8.8: icmp_seq=10 ttl=118 time=10.7 ms
64 bytes from 8.8.8.8: icmp_seq=11 ttl=118 time=10.7 ms
64 bytes from 8.8.8.8: icmp_seq=12 ttl=118 time=10.8 ms
64 bytes from 8.8.8.8: icmp_seq=13 ttl=118 time=10.7 ms
64 bytes from 8.8.8.8: icmp_seq=14 ttl=118 time=10.7 ms
64 bytes from 8.8.8.8: icmp_seq=15 ttl=118 time=10.7 ms
64 bytes from 8.8.8.8: icmp_seq=16 ttl=118 time=10.7 ms
64 bytes from 8.8.8.8: icmp_seq=17 ttl=118 time=10.6 ms
64 bytes from 8.8.8.8: icmp_seq=18 ttl=118 time=10.7 ms
64 bytes from 8.8.8.8: icmp_seq=19 ttl=118 time=10.6 ms
64 bytes from 8.8.8.8: icmp_seq=20 ttl=118 time=10.7 ms
64 bytes from 8.8.8.8: icmp_seq=21 ttl=118 time=10.7 ms
64 bytes from 8.8.8.8: icmp_seq=22 ttl=118 time=10.7 ms
64 bytes from 8.8.8.8: icmp_seq=23 ttl=118 time=10.7 ms
64 bytes from 8.8.8.8: icmp_seq=24 ttl=118 time=10.7 ms
64 bytes from 8.8.8.8: icmp_seq=25 ttl=118 time=10.7 ms
64 bytes from 8.8.8.8: icmp_seq=26 ttl=118 time=10.7 ms
^C
--- 8.8.8.8 ping statistics ---
26 packets transmitted, 26 received, 0% packet loss, time 25046ms
rtt min/avg/max/mdev = 10.655/10.731/10.827/0.073 ms

A problem with DNS maybe? What should I do?

Mooncrater
  • 4,146
  • 4
  • 33
  • 62

14 Answers14

63

All I had to do was add nameserver 8.8.8.8 to the /etc/resolv.conf file. 8.8.8.8 is Google's public free DNS server's IP. So, since a system must know the IP address of a domain name, we have to give it a way to do just that. A public DNS server provides this binding of a domain name to the IP address.

Mooncrater
  • 4,146
  • 4
  • 33
  • 62
22

For Windows 10 User, Go to Settings -> Network and Internet -> Proxy

Disable Automatically detect settings

enter image description here

Ankit Patel
  • 321
  • 2
  • 8
14

If using proxy network and facing same issue then use

pip install --proxy="proxy:portno" numpy

Foe example:

C:\Users\Dell>pip install --proxy="10.50.225.80:3128" numpy

bob
  • 2,674
  • 1
  • 29
  • 46
hawk
  • 141
  • 1
  • 2
  • Thanks, such a life saver ! My Windows automatic proxy set up was already turned off. This finally triggered the installation. – DataBach Jan 28 '22 at 15:50
  • Thank you for the solution, now it works. Previously I had tried to set the proxy globally, by modifying ~/.bashrc, as shown bellow. However it didn't work. export http_proxy="proxy_url:proxy_port" export HTTP_PROXY="proxy_url:proxy_port" export https_proxy="proxy_url:proxy_port" export HTTPS_PROXY="proxy_url:proxy_port" export ftp_proxy="proxy_url:proxy_port" export FTP_PROXY="proxy_url:proxy_port" export all_proxy="proxy_url:proxy_port" export ALL_PROXY="proxy_url:proxy_port" – vcmorini Feb 10 '22 at 13:12
14

I just restarted the network services and then did docker restart. Commands used:

systemctl restart NetworkManager.service
sudo service docker restart
Mooncrater
  • 4,146
  • 4
  • 33
  • 62
Romita Thakur
  • 233
  • 1
  • 3
  • 8
  • 1
    This solution worked for me. I was using Ubuntu 22.04 virtual machine in VMWare. – Kenan Begić Nov 01 '22 at 14:26
  • This worked for me without restarting NetworkManager (so, I only restarted `docker` service). Maybe it was caused by turning my VPN off and back on again some time before running `docker-compose up`. – Vedran Šego Nov 09 '22 at 01:32
7

Check the proxy configuration inside proxy settings. Then use :

 pip install --proxy=http://yourproxyurl:port numpy(Python package name)
vaishali KUNJIR
  • 997
  • 11
  • 9
  • 4
    I found it better to set environment vars for proxy to avoid errors with setup.py for modules. `export http_proxy=; export https_proxy=` – Junaid Feb 03 '21 at 01:46
7

Not an answer to the original question.

Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f7542572828>: Failed to establish a new connection: [Errno -2] Name or service not known',)':

The same warning occurs to me when I was writing Dockerfile.
Obviously, it's the network problem.
However, the result of DNS and ping from host to pip source is fine.
Eventually, I deleted the Dockerfile from the start of the pip part to the end.
After I exec into the container, the network is unable to get the DNS server.

Remind by my coworker, there was a change about iptables.
When a change made to iptables, the server needs to restart the docker engine to make it work.
It could be but not limit to sudo service docker restart
However, hope this answer could save some others' time.

Shihe Zhang
  • 2,641
  • 5
  • 36
  • 57
6

if you are trying to build a docker image and see this error use --network=host at the end of your command.

docker build -t {name} . --network=host
Mooncrater
  • 4,146
  • 4
  • 33
  • 62
mohammadSHP
  • 69
  • 1
  • 2
4

I have this problem when I use VPN. Not sure what's the reason for this, but switching it off solves the problem.

Sergey Ivanov
  • 3,719
  • 7
  • 34
  • 59
  • Restarting docker (see [Romita's answer](https://stackoverflow.com/a/72372200/1667018) above) seems to fix this. – Vedran Šego Nov 09 '22 at 01:33
  • I have the same issue. Did you find out why it would not allow connection on VPN? Are there security vulnerabilities that the network admin, domain admin, or vpn admin would not allow connection for pip or python installation? – ptn77 Jan 19 '23 at 17:54
0

You can close all your proxy programs and leave the Windows proxy section blank. I had this problem with Lantern and Psiphon.

0

I had this problem on Raspbian 10 after intalling network-manager following the instructions in this link:

https://www.giovanni.panozzo.it/guides/raspbian-stretch-network-manager-openvpn.html

After undoing following step, DNS works again!

sudo ln -sf /run/resolvconf/resolv.conf /etc/resolv.conf

(luckily I saved the original file!)

vicmortelmans
  • 616
  • 6
  • 16
0

It's purely network issue. so you just check your network speed for the pip package installations or restart your network and check again with pip install {{package_name}}

Karthikeyan Ganesan
  • 1,901
  • 20
  • 23
0

I ran into this issue using docker build. What is your docker version? Upgrading to the latest version helped me solve the issue!

Docker version 23.0.3
0

If you are on window use this :

py -m pip install --proxy="http://username:passwd@proxy-ip:port" package_name
ross
  • 111
  • 1
  • 2
  • 9
-2

I faced the same issue.

Resolved Turn off the internet then turn it on.

✅ Works for me. It was also a problem with VPN.