"pip config get xxx" fails when PIP_CONFIG_FILE env variable is set
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
- Without the env variable:
pip config get <whatever>works - Set the env variable to the same config file eg
export PIP_CONFIG_FILE=~/.config/pip/pip.conffor instance - 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
- [X] I agree to follow the PSF Code of Conduct.
Also experienced this issue with the following versions: Pip version: 23.0.1 Python version: 3.11.2 OS: ubuntu
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.
Does the specified configuration file actually contain configuration? If not, you can't hope to retrieve any value.
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
Also experienced this issue with the following versions: Pip version: 23.3.1 Python version: 3.10.10 OS: Windows 11
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
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.