How to Fix Windows Pip Access Denied Errors
[Error 5] Access is denied usually happens when pip tries to write .pyd binary modules to the %TEMP% directory (specifically those easy_install-* folders) and Windows blocks it. This is common with packages like mitmproxy or cryptography where dependencies are being compiled or unpacked.The real fix isn't just "running as admin"—it's switching from the pip executable to the python -m pip module. Using the module ensures the process runs under the Python interpreter's own context, avoiding the permission clashes and path conflicts that happen when calling the standalone pip wrapper.
Step-by-step recovery
1. Kill blocking processes: Close VS Code, PyCharm, and any open terminals. If files are locked by a ghost process, nothing will work until you reboot or kill those tasks.
2. Launch PowerShell as Administrator: This is necessary for the initial cleanup, but not necessarily for the install itself.
3. Check your temp folder permissions:
# Check current permissions
icacls $env:TEMP4. Clean the slate and install: Use the --no-cache-dir flag to stop pip from grabbing corrupted or locked cached files.
python -m pip install --upgrade pip
python -m pip install --no-cache-dir mitmproxy5. Nuclear option for stubborn locks: If it still fails, wipe the temp install folders manually.
# Wipe previous failed installation attempts
Remove-Item -Recurse -Force "$env:TEMP\easy_install-*" -ErrorAction SilentlyContinue
Remove-Item -Recurse -Force "$env:TEMP\pip-*" -ErrorAction SilentlyContinue6. Final install (Standard User): Try the install again without admin privileges. Installing as admin can sometimes create files that your normal user account can't modify later.
python -m pip install mitmproxyThe "Clean Slate" Command
If you're stuck in a loop of failed installs, run this block to purge the problematic binaries and force a fresh download:
# Purge conflicting binaries and temp files
python -m pip uninstall -y cryptography cffi
Remove-Item -Recurse -Force "$env:TEMP\easy_install-*", "$env:TEMP\pip-*" -ErrorAction SilentlyContinue
python -m pip install --no-cache-dir --force-reinstall cryptography cffi
python -m pip install --no-cache-dir mitmproxyPractical workflow tips
- Stop using
pipdirectly: In Windows,python -m pipis the only way to be 100% sure you're targeting the correct environment and avoiding permission bugs. - Conda users: If you're on Anaconda/Miniconda, stick to
conda install -c conda-forge mitmproxyfor binary-heavy packages. - Custom Temp Dir: If your system
%TEMP%is a mess, redirect pip to a folder you actually control:
[Environment]::SetEnvironmentVariable("TMPDIR", "C:\temp-pip", "User")
New-Item -ItemType Directory -Path "C:\temp-pip" -Force