Skip to content

Conversation

DenKoren
Copy link

@DenKoren DenKoren commented Sep 2, 2025

When _pick_get_win_folder in platformdirs/windows.py uses registry to find common appdata path and
there is no key in 'HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Common AppData', configuration loading procedure in PIP throws an exception and fails 'install' procedure.

Error example:

  File "C:\example\venv\Lib\site-packages\pip\_internal\configuration.py", line 70, in get_configuration_files
    os.path.join(path, CONFIG_BASENAME) for path in appdirs.site_config_dirs("pip")
                                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\example\venv\Lib\site-packages\pip\_internal\utils\appdirs.py", line 48, in site_config_dirs
    dirval = _appdirs.site_config_dir(appname, appauthor=False, multipath=True)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\example\venv\Lib\site-packages\pip\_vendor\platformdirs\__init__.py", line 146, in site_config_dir
    ).site_config_dir
      ^^^^^^^^^^^^^^^
  File "C:\example\venv\Lib\site-packages\pip\_vendor\platformdirs\windows.py", line 67, in site_config_dir
    return self.site_data_dir
           ^^^^^^^^^^^^^^^^^^
  File "C:\example\venv\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 "C:\example\venv\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

@ichard26
Copy link
Member

ichard26 commented Sep 2, 2025

I'm afraid that I'm asking you to do more work, but have you investigated whether this would be better fixed in platformdirs instead? This seems like the sort of thing that could be handled with a fallback instead of a registry error. Generally, we prefer to upstream changes to our vendored dependencies over carrying patches (for pip or pip's vendored packages) to keep things maintainable.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants