Python pip raising NewConnectionError while installing libraries
Asked Answered
M

16

57

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?

Ministry answered 15/10, 2018 at 11:29 Comment(1)
I am facing this problem on Kaggle not locally. And it's specific to the installation of NLPAUG model. WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7a25f260eb60>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/nlpaug/ ERROR: Could not find a version that satisfies the requirement nlpaug (from versions: none) ERROR: No matching distribution found for nlpaugStarobin
M
83

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.

Ministry answered 15/10, 2018 at 14:33 Comment(8)
Had this exact same issue with WSL and Virtualenv so thank you!Carthusian
Neat solution!!!Soundproof
Also had to restart WSL :)Blowing
This is magic! I have suffered for months with this. Thanks a lotImitation
How to fix this for Windows container?Cabot
1) I actually had to remove the nameserver lines. 2) Just exiting the WSL was not enough for me. I had to use a powershell and do wsl --shutdown to really quit it.Zeeba
@AndreasStorvikStrauman how did you restart wsl?Redcoat
Had to do wsl --shutdown for changes in /etc/resolv.conf file to take effect, as said by @ZeebaWorked
J
29

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

Disable Automatically detect settings

enter image description here

Jolley answered 26/6, 2020 at 14:6 Comment(6)
Classic windows! I had to restart the computer to make this work.Ellga
I just wanted to say that I love you.Taveras
Thanks for the tip. It worked. I didn't have to restart after making this change.Testosterone
This isn't worked for me. Any other suggestion where I might be wrong?Cabot
Unfortunately I don't feel this is much of a solution, as on a company issued laptop proxy settings can be controlled via group policy thus meaning the user doesn't have the ability to just turn off various Windows settingsSeeder
Thank you! I use WSL. I disabled the "Automatically detect settings" and then shut down WSL by running wsl --shutdown then started it by running bash, and it worked!Toga
M
19

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

Maryannemarybella answered 10/12, 2019 at 16:4 Comment(3)
Thanks, such a life saver ! My Windows automatic proxy set up was already turned off. This finally triggered the installation.Joyance
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"Metaxylem
It worked on my company laptop! To find the proxy on Windows I guessed that the port number was 8080 (most of the internal proxies work on port 8080), then I opened cmd and run netstat -a -n and I searched for 8080 with CTRL+F and I looked for an address with state "ESTABLISHED". Then I run pip install --proxy="proxy_found_in_cmd:8080" numpy and it worked!Roseliaroselin
F
19

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

systemctl restart NetworkManager.service
sudo service docker restart
Fawcette answered 25/5, 2022 at 5:8 Comment(2)
This solution worked for me. I was using Ubuntu 22.04 virtual machine in VMWare.Wholewheat
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.Adam
R
14

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
Rabelais answered 13/9, 2022 at 13:47 Comment(1)
this helped me ,i was running the same command but inside the WSL (Ubuntu), thank you @mohammadLemmy
B
9

Check the proxy configuration inside proxy settings. Then use :

 pip install --proxy=http://yourproxyurl:port numpy(Python package name)
Britneybritni answered 11/12, 2019 at 9:31 Comment(2)
I found it better to set environment vars for proxy to avoid errors with setup.py for modules. export http_proxy=<your-proxy:port>; export https_proxy=<your-https-proxy:port>Hightower
This works but for some reason, proxy does not apply to downloading dependencies, only main package is downloaded. For dependencies, I get same errorBruxelles
T
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.

Trejo answered 29/4, 2021 at 9:24 Comment(0)
T
4

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

Thirddegree answered 9/11, 2020 at 10:32 Comment(2)
Restarting docker (see Romita's answer above) seems to fix this.Adam
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?Labradorite
S
1

I resolved a similar issue by updating the DNS configuration to a more reliable one (Google nameservers). Follow the below steps to append it

sudo nano /etc/resolv.conf

Move to the end of the file and add below

nameserver 8.8.8.8
nameserver 8.8.4.4

Save and exit

Note: I was using Ubuntu

Sidero answered 12/6 at 4:45 Comment(0)
L
0

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

Lyndsaylyndsey answered 25/1, 2021 at 13:42 Comment(0)
S
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!)

Suctorial answered 17/6, 2021 at 20:21 Comment(0)
F
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}}

Fiducial answered 28/6, 2022 at 8:14 Comment(0)
Q
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
Quillen answered 10/4, 2023 at 14:45 Comment(0)
P
0

If you are on window use this :

py -m pip install --proxy="http://username:passwd@proxy-ip:port" package_name
Palmation answered 1/7, 2023 at 17:39 Comment(0)
M
0

In my case i needed to add hosts 'pypi.python.org' and 'pypi.org' to firewall' whitelist

Makepeace answered 11/3 at 12:32 Comment(0)
U
0

I know that some other people have pointed out the fact that you can run pip with a proxy, but I'd like to point out that you can do this "globally" too. I am developing in an Ubuntu 20 VM, and for me, running

export http_proxy=[proxy info]
export https_proxy=[proxy info]
pip install flask

worked.

Unleash answered 29/3 at 18:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.