-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Winreg import failure in appdirs #7495
Comments
Current code: def _get_win_folder_from_registry(csidl_name):
import _winreg
shell_folder_name = {
"CSIDL_APPDATA": "AppData",
"CSIDL_COMMON_APPDATA": "Common AppData",
"CSIDL_LOCAL_APPDATA": "Local AppData",
}[csidl_name]
key = _winreg.OpenKey(
_winreg.HKEY_CURRENT_USER,
r"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"
)
directory, _type = _winreg.QueryValueEx(key, shell_folder_name)
return directory Possible alternative: def _get_win_folder_from_registry(csidl_name):
return {
"CSIDL_APPDATA": os.getenv("APPDATA"),
"CSIDL_COMMON_APPDATA": os.getenv("PROGRAMDATA"),
"CSIDL_LOCAL_APPDATA": os.getenv("LOCALAPPDATA"),
}[csidl_name] |
Alternatively, it looks like the 1.4.3 release uses slightly better handling of the imports to special-case PY3 (which personally I don't agree with - PY2 is the special case - but if you want to do the direct-vendor thing then simply updating should be okay for now). |
Hmm, it looks pip 19.3.1 should already be using 1.4.3; something might be off here… https://github.com/pypa/pip/blob/19.3.1/src/pip/_vendor/appdirs.py It might be worthwhile to submit the environment variable method to upstream though. I’m kind of surprised appdirs doesn’t do that already. |
Yup, cf #6040 |
I think #7501 also resolves this because the vendored appdirs uses the correct import. |
Environment
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
DLLs\_ctypes.pyd
to any other name, or move it elsewhere. (Or any other mechanism you like to prevent it from being imported)pip --version
Output
The text was updated successfully, but these errors were encountered: