Winreg import failure in appdirs
See original GitHub issueEnvironment
- 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
- Rename
DLLs\_ctypes.pyd
to any other name, or move it elsewhere. (Or any other mechanism you like to prevent it from being imported) - Then run
pip --version
- 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:
- Created 4 years ago
- Comments:5 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yup, cf #6040
I think #7501 also resolves this because the vendored appdirs uses the correct import.