Skip to content

Winreg import failure in appdirs #7495

@zooba

Description

@zooba

Environment

  • pip version: 19.3.1
  • Python version: 3.7.5 (modified)
  • OS: Windows 10

The version of Python I am using is modified for security. Most importantly, ctypes is removed.

Description
Without ctypes available, appdirs will automatically use the _get_win_folder_from_registry function.

However, this function has not been updated for Python 3's winreg module - it tries/fails to import _winreg (the Python 2.x name).

Expected behavior

How to Reproduce

  1. Rename DLLs\_ctypes.pyd to any other name, or move it elsewhere. (Or any other mechanism you like to prevent it from being imported)
  2. Then run pip --version
  3. An error occurs.

Output

(testenv) PS C:\testenv> pip --version
  File "C:\Python37_x64\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Python37_x64\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\testenv\Scripts\pip.exe\__main__.py", line 5, in <module>
  File "c:\testenv\lib\site-packages\pip\_internal\main.py", line 13, in <module>
    from pip._internal.cli.autocompletion import autocomplete
  File "c:\testenv\lib\site-packages\pip\_internal\cli\autocompletion.py", line 11, in <module>
    from pip._internal.cli.main_parser import create_main_parser
  File "c:\testenv\lib\site-packages\pip\_internal\cli\main_parser.py", line 7, in <module>
    from pip._internal.cli import cmdoptions
  File "c:\testenv\lib\site-packages\pip\_internal\cli\cmdoptions.py", line 25, in <module>
    from pip._internal.locations import USER_CACHE_DIR, get_src_prefix
  File "c:\testenv\lib\site-packages\pip\_internal\locations.py", line 28, in <module>
    USER_CACHE_DIR = appdirs.user_cache_dir("pip")
  File "c:\testenv\lib\site-packages\pip\_internal\utils\appdirs.py", line 47, in user_cache_dir
    path = os.path.normpath(_get_win_folder("CSIDL_LOCAL_APPDATA"))
  File "c:\testenv\lib\site-packages\pip\_internal\utils\appdirs.py", line 207, in _get_win_folder_from_registry
    import _winreg
ModuleNotFoundError: No module named '_winreg'

Metadata

Metadata

Assignees

No one assigned

    Labels

    auto-lockedOutdated issues that have been locked by automationstate: awaiting PRFeature discussed, PR is neededtype: enhancementImprovements to functionality

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions