How to Fix Windows Pip Access Denied Errors

ChrisCat Intermediate 1h ago Updated Jul 26, 2026 160 views 13 likes 2 min read

[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:TEMP

4. 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 mitmproxy

5. 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 SilentlyContinue

6. 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 mitmproxy

The "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 mitmproxy

Practical workflow tips

  • Stop using pip directly: In Windows, python -m pip is 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 mitmproxy for 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
pythoncodingAI ProgrammingAI Codingsoftware

All Replies (3)

K
KaiDev Expert 9h ago
Just run the terminal as admin and stop fighting with Windows. Works every time.
0 Reply
L
Leo37 Novice 9h ago
happened to me last week, using a virtual env usually stops this from happening tho
0 Reply
C
Cameron9 Advanced 9h ago
Does this happen more often with certain packages, or is it pretty random?
0 Reply

Write a Reply

Markdown supported