3
Windows Version: 10 Pro, Version 20H2 (OS Build 19042.1165)
WSL Version: 2
Ubuntu Version: 20.04

I'm working with WSL 2 on my Windows laptop and am trying to install some Python packages (pytest) using pip. Specifically, I create an Anaconda environment with Python=3.7 and try to install the package within that environment. However, the command hangs for a while and then I get this warning:

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 0x7f608eadaf90>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/pytest/

The same thing repeats until I press Ctrl-C. I originally had WSL version 1 installed and upgraded to WSL version 2. When I was using WSL version 1, I didn't have this problem. When I searched online, it seems several people have had similar (but slightly different in terms of the actual exception) problems, but I have not come across a solution that works for me.

I also found out that this is not just limited to pip. I'm unable to clone gitlab (from work) repositories as well. It results in a fatal error of not able to find the repository. I found a potential fix from here. It says to add a nameserver to my /etc/resolv.conf. This is my current /etc/resolv.conf:

nameserver 1.1.1.1

I manually added the last line. As indicated in the file, I created /etc/wsl.conf in order to stop this file automatically regnerate:

[network]
generateResolvConf = false

This works, howver, it takes a while for the command I issue to get going (git clone, pip etc).

I don't really understand what the issue is and why adding nameserver 1.1.1.1 solves it or why its being slow. Is there a fix for this?

Thanks.

shaun
  • 560
  • 1
  • 11
  • 29
  • Is it really `pip` that's the problem (as in your title) or is this more related to installing/configuring Anaconda under WSL *using* `pip`? Does `pip` work for other packages? If so, I'd recommend editing the title to try to get more eyes focused on the right problem. – NotTheDr01ds Aug 26 '21 at 21:15
  • Thanks for your reply. This is not an Anaconda issue. Anaconda is just a virtual environment that I'm using to separate my Python installations. This was working fine before when I was using WSL 1. I was using Anaconda back then as well. – shaun Aug 27 '21 at 01:15
  • That makes sense - Thanks for the clarification. That rings a bell now that I think about it, but I'm not sure if I'm remembering the same issue or not -- Probably not, if a nameserver change improved things. It sounds like this is *specific* to `pip` for you, right? No slowdown (after the 1.1.1.1 nameserver change) in other things like `wget` or `sudo apt update && sudo apt upgrade`? – NotTheDr01ds Aug 27 '21 at 02:54

2 Answers2

0

I used VM Ware Player having the same problems with frequent failures to name resolution and upgrading to WM Player V17 fixed is today.

Synopsis
  • 190
  • 10
-1

I ended up solving this by just adding nameserver 1.1.1.1 to my /etc/resolv.conf as suggested here. While it works and installs what its supposed to, it just takes a long time to begin downloading.

shaun
  • 560
  • 1
  • 11
  • 29
  • Possible that the nameserver fix unblocked you on one issue only to run into another. Try `export PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring` and making sure you don't have `DISPLAY` set. See [this Github issue](https://github.com/pypa/pip/issues/9061#issuecomment-717721223). – NotTheDr01ds Aug 27 '21 at 03:12
  • Thanks. How do I make sure I don't have `DISPLAY`. This is not a pip only issue anymore, I'm actually unable to clone repos without the `nameserver 1.1.1.1` added at `/etc/resolv.conf`. Even then it takes a while to get going and the change to `/etc/resolv.conf` doesn't carry over sessions. – shaun Aug 27 '21 at 11:51
  • Well, `unset DISPLAY` or `export -n DISPLAY`, but I would only expect that to help if the `pip` problem was related to the keyring mentioned in that Github issue. This really does sound like a DNS resolution problem now. Any chance you are running a VPN in Windows? (Don't forget to @tag me in replies to make sure I get notified. You automatically get notified as the answer owner, but I may not). – NotTheDr01ds Aug 27 '21 at 13:44
  • Ah, I remember that (before edit) you mentioned DirectAccess. Did you turn that back on? Not sure exactly how DCA works -- Does it change the Windows nameserver? – NotTheDr01ds Aug 27 '21 at 14:03
  • @NotTheDr01ds Yes. DirectAccess is back on. But it seems that DirectAccess is not a problem. I do have GlobalProtect which when I use will cause these problem. But I don't enable to GlobalProtect when I work on this project. DirectAccess is always enabled, but as I mentioned it doesn't seem like a problem afaict – shaun Aug 27 '21 at 18:08
  • Right, and while I'm feeling there's some connection to the Windows networking end (DCA or GlobalProtect), I don't want to give up on root-causing it. Just want to clarify, at this point, do *all* networking commands time out (you mentioned repos now)? Basic `ping`? Do you have another device on the LAN you can `ping`? Does it stall then or does it stall when you `ping 1.1.1.1`? Or is it just `pip` and `git`? Sorry, at this point I'm at a loss, but with no one else offering any ideas, maybe we'll stumble in the right direction eventually :). – NotTheDr01ds Aug 27 '21 at 18:22
  • 1
    @NotTheDr01ds At this point after adding `nameserver 1.1.1.1` to my `/etc/resolv.conf` (and not having it regenerate every session) everything is working. But it takes a couple of seconds for the `git clone` and `pip install` to start the process. `ping` (both `www.google.com` & `1.1.1.1`) is working instantaneously. I agree with you. There seems to be so many versions of this problems out there. I'm not sure whats causing it, but I've found a temporary solution and maybe as you say we'll get a better solution eventually. Thanks for the help! – shaun Aug 27 '21 at 19:20