Skip to content
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

pip install Windows registry error Access is denied #12769

Open
1 task done
Enchiridion opened this issue Jun 16, 2024 · 9 comments
Open
1 task done

pip install Windows registry error Access is denied #12769

Enchiridion opened this issue Jun 16, 2024 · 9 comments
Labels
good first issue A good item for first time contributors to work on OS: windows Windows specific state: awaiting PR Feature discussed, PR is needed type: bug A confirmed bug or unintended behavior

Comments

@Enchiridion
Copy link

Description

When installing a package using pip, it fails with the error: PermissionError: [WinError 5] Access is denied. I used Process Monitor to trace the error to a registry key it couldn't access. Instead of pip skipping the inaccessible key and continuing the installation, it failed. It was failing over 3 registry keys I had earlier removed my own access to to prevent Google Drive from constantly recreating new ShellNew entries (a known and very annoying issue with GD), one of them is HKEY_CLASSES_ROOT\.gdoc. Not sure why pip is enumerating all the entries in HKEY_CLASSES_ROOT but I think it should skip any it can't access.

Expected behavior

For the install to successfully complete. If pip can't access a registry key in HKEY_CLASSES_ROOT it should skip and continue.

pip version

24.0

Python version

3.12.4

OS

Windows 11

How to Reproduce

  1. Use regedit to modifying the permissions of any key in HKEY_CLASSES_ROOT by marking the Administrators group with Deny permission for Full Control and Read.
  2. Try to install any package using pip.

Output

ERROR: Could not install packages due to an OSError.
Check the permissions.
Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.1264.0_x64__qbz5n2kfra8p0\Lib\site-packages\pip\_internal\commands\install.py", line 377, in run
    requirement_set = resolver.resolve(
                      ^^^^^^^^^^^^^^^^^
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.1264.0_x64__qbz5n2kfra8p0\Lib\site-packages\pip\_internal\resolution\resolvelib\resolver.py", line 179, in resolve
    self.factory.preparer.prepare_linked_requirements_more(reqs)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.1264.0_x64__qbz5n2kfra8p0\Lib\site-packages\pip\_internal\operations\prepare.py", line 552, in prepare_linked_requirements_more
    self._complete_partial_requirements(
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.1264.0_x64__qbz5n2kfra8p0\Lib\site-packages\pip\_internal\operations\prepare.py", line 487, in _complete_partial_requirements
    self._prepare_linked_requirement(req, parallel_builds)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.1264.0_x64__qbz5n2kfra8p0\Lib\site-packages\pip\_internal\operations\prepare.py", line 613, in _prepare_linked_requirement
    local_file = File(file_path, content_type=None)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.1264.0_x64__qbz5n2kfra8p0\Lib\site-packages\pip\_internal\operations\prepare.py", line 87, in __init__
    self.content_type = mimetypes.guess_type(path)[0]
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.1264.0_x64__qbz5n2kfra8p0\Lib\mimetypes.py", line 309, in guess_type
    init()
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.1264.0_x64__qbz5n2kfra8p0\Lib\mimetypes.py", line 371, in init
    db.read_windows_registry()
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.1264.0_x64__qbz5n2kfra8p0\Lib\mimetypes.py", line 256, in read_windows_registry
    _mimetypes_read_windows_registry(add_type)
PermissionError: [WinError 5] Access is denied
Remote version of pip: 24.0
Local version of pip:  24.0
Was pip installed by pip? True

Code of Conduct

@Enchiridion Enchiridion added S: needs triage Issues/PRs that need to be triaged type: bug A confirmed bug or unintended behavior labels Jun 16, 2024
@ichard26 ichard26 added OS: windows Windows specific good first issue A good item for first time contributors to work on state: awaiting PR Feature discussed, PR is needed and removed S: needs triage Issues/PRs that need to be triaged labels Jun 22, 2024
@ichard26
Copy link
Member

We can add a internal utility function which wraps mimetypes.guess_type and returns (None, None) on an OSError, although care needs to be taken that pip degrades gracefully when the mimetype fails to be deduced.

@georgepr0xy
Copy link

Ensure you are using the latest version of pip. Sometimes, updating pip can resolve unexpected issues:

Use the below command

python -m pip install --upgrade pip

@georgepr0xy
Copy link

Since the issue is caused by restricted registry keys, you might need to temporarily restore access to these keys:

Open the Registry Editor (regedit).

1.Navigate to the problematic keys, such as HKEY_CLASSES_ROOT.gdoc.
2.Right-click on the key, select "Permissions," and restore your access.
3.Run the pip install command again.
4.Revoke the permissions again after the installation is complete.

@Enchiridion
Copy link
Author

@georgepr0xy This was on a fresh install of Python 3. I tried to update pip, but due to pip quitting on the first registry error, it was unable to update itself.

Temporarily changing the reg key permissions is what I did to get around the issue for now.

@georgepr0xy
Copy link

Since pip is failing due to registry errors, manually updating pip might help:

  1. Download the get-pip.py script from the official [pip website] (https://bootstrap.pypa.io/get-pip.py).
  2. Open Command Prompt as an administrator and run the following command:
    python get-pip.py

@georgepr0xy
Copy link

You might consider modifying the pip source code temporarily to skip over registry keys it can't access. This is a bit more advanced and involves editing the pip package files:

Locate pip installation:
Find where pip is installed. It is typically located in Lib\site-packages\pip within your Python directory.

Modify the code:
Identify the part of the code where pip might be accessing the registry (this might be a bit complex as pip does not typically interact with the registry directly). Insert try-except blocks to catch and ignore permission errors.

@ichard26
Copy link
Member

ichard26 commented Jul 1, 2024

@georgepr0xy Are you copying and pasting AI responses? If so, I ask that it stops as it simply serves to add noise to this issue, failing to provide a proper solution to this issue.

@Kolukuluru33
Copy link

Modify the permissions of the problematic registry keys to grant read access temporarily, install the package, and then revert the permissions. Alternatively, run the pip installation with elevated privileges using an Administrator command prompt.

@Shrinkhal01
Copy link

Shrinkhal01 commented Jul 3, 2024

You can first navigate to the directory by opening the terminal/commandprompt using admin account[run as administrator] and then go and try that again the same error i encountered and did this (it worked )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue A good item for first time contributors to work on OS: windows Windows specific state: awaiting PR Feature discussed, PR is needed type: bug A confirmed bug or unintended behavior
Projects
None yet
Development

No branches or pull requests

5 participants