question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Winreg import failure in appdirs

See original GitHub issue

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'

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
xavfernandezcommented, Dec 18, 2019

something might be off here…

Yup, cf #6040

0reactions
uranusjrcommented, Dec 27, 2019

I think #7501 also resolves this because the vendored appdirs uses the correct import.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python import error ModuleNotFoundError: No module named ...
importError: no module named _winreg python3. As it says in the _winreg documentation, it has been renamed to winreg in Python 3.0.
Read more >
Python Examples of winreg.QueryValueEx - ProgramCreek.com
In case this fails, default is returned. """ try: # Use win32api if available from win32api import RegQueryValueEx except ImportError: # On Python...
Read more >
.virtualenvs/djangodev/Lib/site-packages/pip/_vendor/appdirs.py ...
See <http://github.com/ActiveState/appdirs> for details and usage. ... See the Vista-Fail note above for why. ... import winreg as _winreg.
Read more >
https://bugs.gentoo.org/attachment.cgi?id=402120
QueryValue(hkey, '') /usr/lib64/python3.4/importlib/_bootstrap.py: setattr(self_module, '_winreg', winreg_module) Binary file ...
Read more >
0dd47768f97a6cae4cb70d2ab7...
An error occurred while loading commit signatures ... appdirs.py ... try: import winreg as _winreg except ImportError: # pylint: ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found