pip icon indicating copy to clipboard operation
pip copied to clipboard

"pip config get xxx" fails when PIP_CONFIG_FILE env variable is set

Open AtomBaf opened this issue 3 years ago • 7 comments

Description

When an explicit file location is set for the configuration of pip with the PIP_CONFIG_FILE environment variable, the result of pip config get <key> fails

Expected behavior

The key should be retrieved, using all the resolution possible, PIP_CONFIG_FILE env included.

pip version

22.3.1

Python version

3.9.13

OS

rocky linux

How to Reproduce

  1. Without the env variable: pip config get <whatever> works
  2. Set the env variable to the same config file eg export PIP_CONFIG_FILE=~/.config/pip/pip.conf for instance
  3. Now pip config get <whatever> will fail

Note that the pip config debug and pip config list are apparently correctly working. Also not that the same problem happens when using pip config set ...

Output

pip config get global.index-url
ERROR: No such key - global.index-url

Code of Conduct

AtomBaf avatar Jan 05 '23 14:01 AtomBaf

Also experienced this issue with the following versions: Pip version: 23.0.1 Python version: 3.11.2 OS: ubuntu

philblckwd avatar Mar 20 '23 23:03 philblckwd

I've been trying to figure this out too. Here's what I've figured out, but I'm not sure what the fix is:

$ pip config -vvv set global.foo bar
Skipping file '/home/coder/.config/pip/pip.conf' (variant: env)
Skipping file '/etc/xdg/pip/pip.conf' (variant: global)
Skipping file '/etc/pip.conf' (variant: global)
Skipping file '/opt/pyenv/versions/3.9.16/pip.conf' (variant: site)
Will be working with user variant only
ERROR: Fatal Internal error [id=2]. Please report as a bug.

It seems like having the environment variable set causes there to be an env variant, but no user variant. This then conflicts with pip's default behavior to get/set values from the user variant.

nvachhar avatar May 30 '23 21:05 nvachhar

Does the specified configuration file actually contain configuration? If not, you can't hope to retrieve any value.

chrysle avatar Sep 26 '23 12:09 chrysle

Yes for sure!

example

➜ PIP_CONFIG_FILE=./uuu python3 -m pip config list                
:env:.config-file='./uuu'
global.index-url='https://download.zope.org/ppix'
global.timeout='60'
➜ PIP_CONFIG_FILE=./uuu python3 -m pip config get global.index-url
ERROR: No such key - global.index-url

AtomBaf avatar Sep 26 '23 21:09 AtomBaf

Also experienced this issue with the following versions: Pip version: 23.3.1 Python version: 3.10.10 OS: Windows 11

Jordan-Haidee avatar Oct 28 '23 08:10 Jordan-Haidee

After test, I find something interesting. Different from $env:PIP_CONFIG_FILE, when $env:PIP_CONFIG is set, everything is OK. And runnnig pip config list can scan this variable successfully. Then pip config set and pip config get is done. I really feel strange.

➜ pip config list
:env:.config='C:\\Users\\dell\\AppData\\Roaming\\pip\\pip.ini'
global.cache-dir='F:\\pip_cache'
global.extra-index-url='https://pypi.tuna.tsinghua.edu.cn/simple'
global.index-url='http://mirrors.aliyun.com/pypi/simple'
global.timeout='500'
install.trusted-host='mirrors.aliyun.com'
~ via 🐍 v3.10.10
➜ pip config get global.timeout
500
~ via 🐍 v3.10.10
➜ pip config set global.timeout 120
Writing to C:\Users\dell\AppData\Roaming\pip\pip.ini

Jordan-Haidee avatar Oct 28 '23 08:10 Jordan-Haidee

Weirdly enough I have the issue even without the env var set. In my case I get the same error when putting pip.conf at /etc/pip.conf in my CI/CD pipeline but it goes away when I moved it to ~/.config/pip/pip.conf.

I noticed the same behavior as you where pip itself and specifically pip config debug both worked just not pip config get globa.index-url.

ggeorge-pros avatar Jun 28 '24 22:06 ggeorge-pros