Skip to content

FileNotFoundError on Windows when queries HKEY_CURRENT_USER for Common AppData #13708

@howardhey

Description

@howardhey

Description

When attempting to install any package using pip on Windows, the command fails with a FileNotFoundError. The error originates from the platformdirs library’s fallback registry query function, which incorrectly looks for the Common AppData registry value in HKEY_CURRENT_USER instead of HKEY_LOCAL_MACHINE.

The Common AppData value is correctly present in HKEY_LOCAL_MACHINE but does not exist in HKEY_CURRENT_USER by default, causing the fallback function to crash instead of falling back to the correct registry hive.

The import point is I use miniforge and all the steps and erros are in miniforge environment.

I'm sure I updated all the packages to latest versions.

I've already noticed there are some similar issues like #12532, and the point is that "pip_vendor" is not a standard version of pip which might be changed by miniforge or anaconda or some else. But I checked my error information, and the "site-packages\pip" location shows this is a standard version of pip (at least it looks like a standard version).

Or maybe miniforge changes pip in its remote library but still shows "pip" locally? That will be so weird.

Expected behavior

No response

pip version

25.3

Python version

3.14.2

OS

Windows11

How to Reproduce

  1. Activate miniforge env.
  2. Run pip install .
  3. The command fails with the traceback above.

Output

(genai-api-dev) C:\Users\Howard>pip install zai-sdk
Traceback (most recent call last):
  File "D:\miniforge3\envs\genai-api-dev\Scripts\pip-script.py", line 9, in <module>
    sys.exit(main())
             ~~~~^^
  File "D:\miniforge3\envs\genai-api-dev\Lib\site-packages\pip\_internal\cli\main.py", line 65, in main
    cmd_name, cmd_args = parse_command(args)
                         ~~~~~~~~~~~~~^^^^^^
  File "D:\miniforge3\envs\genai-api-dev\Lib\site-packages\pip\_internal\cli\main_parser.py", line 79, in parse_command
    general_options, args_else = parser.parse_args(args)
                                 ~~~~~~~~~~~~~~~~~^^^^^^
  File "D:\miniforge3\envs\genai-api-dev\Lib\site-packages\pip\_internal\cli\parser.py", line 283, in get_default_values
    self.config.load()
    ~~~~~~~~~~~~~~~~^^
  File "D:\miniforge3\envs\genai-api-dev\Lib\site-packages\pip\_internal\configuration.py", line 126, in load
    self._load_config_files()
    ~~~~~~~~~~~~~~~~~~~~~~~^^
  File "D:\miniforge3\envs\genai-api-dev\Lib\site-packages\pip\_internal\configuration.py", line 257, in _load_config_files
    config_files = dict(self.iter_config_files())
  File "D:\miniforge3\envs\genai-api-dev\Lib\site-packages\pip\_internal\configuration.py", line 352, in iter_config_files
    config_files = get_configuration_files()
  File "D:\miniforge3\envs\genai-api-dev\Lib\site-packages\pip\_internal\configuration.py", line 72, in get_configuration_files
    os.path.join(path, CONFIG_BASENAME) for path in appdirs.site_config_dirs("pip")
                                                    ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^
  File "D:\miniforge3\envs\genai-api-dev\Lib\site-packages\pip\_internal\utils\appdirs.py", line 47, in site_config_dirs
    dirval = _appdirs.site_config_dir(appname, appauthor=False, multipath=True)
  File "D:\miniforge3\envs\genai-api-dev\Lib\site-packages\pip\_vendor\platformdirs\__init__.py", line 146, in site_config_dir
    ).site_config_dir
      ^^^^^^^^^^^^^^^
  File "D:\miniforge3\envs\genai-api-dev\Lib\site-packages\pip\_vendor\platformdirs\windows.py", line 67, in site_config_dir
    return self.site_data_dir
           ^^^^^^^^^^^^^^^^^^
  File "D:\miniforge3\envs\genai-api-dev\Lib\site-packages\pip\_vendor\platformdirs\windows.py", line 56, in site_data_dir
    path = os.path.normpath(get_win_folder("CSIDL_COMMON_APPDATA"))
                            ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\miniforge3\envs\genai-api-dev\Lib\site-packages\pip\_vendor\platformdirs\windows.py", line 209, in get_win_folder_from_registry
    directory, _ = winreg.QueryValueEx(key, shell_folder_name)
                   ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [WinError 2] The system cannot find the file specified.

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions