Azure / azure-cli

Azure Command-Line Interface
MIT License
4.01k stars 2.98k forks source link

Impossible to install any extensions #29630

Open eltitano opened 2 months ago

eltitano commented 2 months ago

Describe the bug

You cannot install extensions. Some registry entry is missing: path = os.path.normpath(get_win_folder("CSIDL_COMMON_APPDATA")) FileNotFoundError: [WinError 2]

Seems to be Python related.

Related command

az extension add --name XY, i.e. az extension add --name azure-iot

Errors

directory, _ = winreg.QueryValueEx(key, shell_folder_name)

Issue script & Debug output

directory, _ = winreg.QueryValueEx(key, shell_folder_name)

Expected behavior

az extension add --name azure-iot -> SUCCESS

Environment Summary

azure-cli 2.62.0

core 2.62.0 telemetry 1.1.0

Dependencies: msal 1.28.1 azure-mgmt-resource 23.1.1

Additional context

Love you guys. Made my day...

yonzhan commented 2 months ago

Thank you for opening this issue, we will look into it.

github-actions[bot] commented 2 months ago

Here are some similar issues that might help you. Please check if they can solve your problem.

bebound commented 2 months ago

What's the output of this in powershell?

cd "C:\Program Files\Microsoft SDKs\Azure\CLI2"
./python.exe -m site 

If you see extra folders other than this, then the Python you installed is interfering with CLI's bundled Python. As a workaround, rename the extra folders during extension installation and revert it afterward.

sys.path = [
    'C:\\Program Files\\Microsoft SDKs\\Azure\\CLI2',
    'C:\\Program Files\\Microsoft SDKs\\Azure\\CLI2\\python311.zip',
    'C:\\Program Files\\Microsoft SDKs\\Azure\\CLI2\\Lib',
    'C:\\Program Files\\Microsoft SDKs\\Azure\\CLI2\\Lib\\site-packages',
    'C:\\Program Files\\Microsoft SDKs\\Azure\\CLI2\\Lib\\site-packages\\win32',
    'C:\\Program Files\\Microsoft SDKs\\Azure\\CLI2\\Lib\\site-packages\\win32\\lib',
    'C:\\Program Files\\Microsoft SDKs\\Azure\\CLI2\\Lib\\site-packages\\Pythonwin',
]
USER_BASE: 'C:\\Users\\hanglei\\AppData\\Roaming\\Python' (doesn't exist)
USER_SITE: 'C:\\Users\\hanglei\\AppData\\Roaming\\Python\\Python311\\site-packages' (doesn't exist)
ENABLE_USER_SITE: True
alekseivorobev commented 1 month ago

key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, r"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders")

Code in Microsoft SDKs\Azure\CLI2\Lib\site-packages\pip_vendor\platformdirs\windows.py looks for registry keys only in current user tree but some of the keys like common appdata are located in local_machine tree.