You are not logged in.

#1 2025-03-14 02:23:24

ThatOneGenie
Member
Registered: 2024-06-13
Posts: 10

[SOLVED] Pip Not Working In Venv

I am running into a persistent issue with pip being unable to do anything within venvs. It seems that pip is unable to reach pypi and is failing to establish an internet connection. Here is an example of the error output:

$ pip install --upgrade pip
Looking in indexes: https://__token__:****@{GITLAB_INSTANCE}/api/v4/groups/{GROUP_ID}/-/packages/pypi/simple
Requirement already satisfied: pip in ./Test/lib/python3.13/site-packages (24.3.1)
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 0x73e42b18f0e0>: Failed to establish a new connection: [Errno -2] Name or service not known')': /api/v4/groups/%7BGROUP_ID%7D/-/packages/pypi/simple/pip/
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 0x73e42b1534d0>: Failed to establish a new connection: [Errno -2] Name or service not known')': /api/v4/groups/%7BGROUP_ID%7D/-/packages/pypi/simple/pip/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x73e42b153750>: Failed to establish a new connection: [Errno -2] Name or service not known')': /api/v4/groups/%7BGROUP_ID%7D/-/packages/pypi/simple/pip/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x73e42b1539d0>: Failed to establish a new connection: [Errno -2] Name or service not known')': /api/v4/groups/%7BGROUP_ID%7D/-/packages/pypi/simple/pip/
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 0x73e42b153c50>: Failed to establish a new connection: [Errno -2] Name or service not known')': /api/v4/groups/%7BGROUP_ID%7D/-/packages/pypi/simple/pip/

I have done the following in an attempt to remedy this issue:

  • Added authentication to GitHub with SSH Keys through the GitHub CLI

  • reinstalled python-urllib3

  • verified integrity of python files

  • checked and verified DNS and networkmanager cofigurition is correct

As per this post which documents similar issues, I have confirmed that my network and DNS settings are correct. I can successfully ping google.com and resolvectl status seems to show that my DNS is set up properly. I don't want to post the full output here, but I will give some specifics:

 Global
          Protocols: +LLMNR +mDNS -DNSOverTLS DNSSEC=no/unsupported
          resolv.conf mode: foreign
         Current DNS Server: <My ISPs DNS>
         Fallback DNS Servers: 1.1.1.1#cloudflare-dns.com 9.9.9.9#dns.quad9.net 8.8.8.8#dns.google  2606:4700:4700::1111#cloudflare-dns.com
                      2620:fe::9#dns.quad9.net 2001:4860:4860::8888#dns.google
         DNS Domain: <My ISP>
...
...
Link 3 (wifi)
         Current Scopes: DNS LLMNR/IPv4 LLMNR/IPv6 mDNS/IPv4 mDNS/IP
         Protocols: +DefaultRoute +LLMNR +mDNS -DNSOverTLS DNSSEC=no/unsupported
         DNS Servers: <My ISPs DNS Server>
         Default Route: yes

I have genuinely run out of ideas as to what might be causing this. I need to be able to use pip within environments to build dev environments. I recently uninstalled docker, as I was having difficulty setting it up and it was interfering with with other projects while not properly set up. Could that be the problem? Any help would be appreciated, especially as this seems more like a networking/kernel level issue, rather than one with python. Thanks.

Last edited by ThatOneGenie (2025-04-16 06:10:49)

Offline

#2 2025-03-14 15:35:48

twelveeighty
Member
Registered: 2011-09-04
Posts: 1,313

Re: [SOLVED] Pip Not Working In Venv

Are you actually inside a venv when you run `pip install`? Your posted snippet's prompt doesn't look like you are. It also looks like none of the replacement variables (__token__, GROUP_ID, etc) are working, so it would be no surprise the URL resolves to garbage.

Offline

#3 2025-03-14 15:44:35

mithrial
Member
Registered: 2017-03-05
Posts: 79

Re: [SOLVED] Pip Not Working In Venv

Did you intentionally change the index url?

Offline

#4 2025-03-14 17:02:59

ReDress
Member
From: Nairobi
Registered: 2024-11-30
Posts: 133

Re: [SOLVED] Pip Not Working In Venv

twelveeighty wrote:

Are you actually inside a venv when you run `pip install`? Your posted snippet's prompt doesn't look like you are.

Wondered the same thing but then decide to give the OP some benefit of doubt/credit - heh

Offline

#5 2025-03-17 00:44:25

ThatOneGenie
Member
Registered: 2024-06-13
Posts: 10

Re: [SOLVED] Pip Not Working In Venv

twelveeighty wrote:

Are you actually inside a venv when you run `pip install`? Your posted snippet's prompt doesn't look like you are. It also looks like none of the replacement variables (__token__, GROUP_ID, etc) are working, so it would be no surprise the URL resolves to garbage.

Yes, I can confirm I am in a venv. I have both created and ran a venv manually as well as done it thorugh virtualenvwrapper. Just didn't want to post my name when copy/pasting from bash. Sorry for the confusion.

mithrial wrote:

Did you intentionally change the index url?

No. I am not well enough informed when it comes to networking. I leave all DNS/IP management to network-manager. Especially since I have to use eduroam at school.

I do have spyder installed as an IDE, which I know uses conda for distribution. However, I believe on arch it does not use conda and instead just comes packaged with the dependencies, and spyder on my system is not using conda as it's python interpreter (or at least a python interpreter from conda, if that makes sense-its using my normal python interpreter). I don't see any conda versions on my system, but could that be causing the issue? I mostly think it has to do with when I tried to install docker.

Offline

#6 2025-04-16 06:08:14

ThatOneGenie
Member
Registered: 2024-06-13
Posts: 10

Re: [SOLVED] Pip Not Working In Venv

I have finally solved the issue, and would like to post the solution here for anyone who experiences similar issues.

Somehow, my global index-url for pip got set to a gitlab instance url. I don't use gitlab, so what I believe was occurring was that pip was unable to authenticate with gitlab as there was no valid authentication. My best guess as to the token that was present was that it was a GitHub personal access token, but I am still unsure.

In order to resolve this issue, first run the following:

$ python -m pip config debug

This will have output which may look like the following:

env_var:
env:
global:
  /home/uname/.config/kdedefaults/pip/pip.conf, exists: False
  /etc/xdg/pip/pip.conf, exists: False
  /etc/pip.conf, exists: False
site:
  /usr/pip.conf, exists: False
user:
  /home/uname/.pip/pip.conf, exists: False
  /home/uname/.config/pip/pip.conf, exists: True
    global.index-url: https://__token__:{GITLAB_TOKEN}@{GITLAB_INSTANCE}/api/v4/groups/{GROUP_ID}/-/packages/pypi/simple

In order to fix this, I simply changed the global.index-url to the pip default. There are multiple ways this can be done, and multiple URLs which can be used (if you require keyring access or HTTP auth, pip has documentation for this). To change this URL, run the following command:

$ python -m pip config --user set global.index-url https://pypi.org/simple/ 

This will change the user index-url to the default pypi URL, as seen here

Changing this configuration setting has since resolved all issues with pip. Hope this can help anyone in the future. I have marked this discussion as solved.

Offline

Board footer

Powered by FluxBB