Python / Fix 'Access is denied' When Installing with pip on Windows
When pip reports [WinError 5] Access is denied on Windows, first inspect the failed file path and the Python used for installation. If the target is a protected global site-packages folder, create a virtual environment in a writable project folder and run pip with its Python. Files in use and blocked temporary locations require their own diagnosis; administrator execution is not a universal fix.
Read the failed path alongside the error number
Windows error code 5 means access was denied. Read pip’s final error to see which file it could not create or replace. A Python folder under Program Files and a temporary folder need different checks.
| Failed target | Check | Next action |
|---|---|---|
| Global Python Lib\site-packages | Selected Python and write access | Separate installation into a project virtual environment |
| Scripts executable or existing package file | Relevant programs using it and blocking records | Close only the relevant program and retry in the same environment |
| Temp, cache, or another working folder | Permissions, space, and security policy there | Investigate that location and request policy review if needed |
| Installation succeeds but import fails | Installing and running interpreters match | Compare interpreter path and package Location |
This is a diagnostic order, not proof of a cause from a path alone. On managed computers, follow the approved environment and installation policy. Do not broadly unlock system folders or disable security software to bypass the error.
Identify which Python runs pip
Run these commands in Windows PowerShell, not in a Python prompt showing >>>. If py -3 is unavailable, replace it with your installed Python executable or a python command pointing to it. With several versions, select the intended interpreter explicitly.
py -3 -c "import sys; print(sys.executable)"
py -3 -m pip --version
The first line shows the executable; the second shows pip’s version, location, and Python version. python -m pip runs the module with the selected interpreter and avoids a bare pip command pointing elsewhere. Compare it with the interpreter that produced the error.
Install and verify in a project virtual environment
Open PowerShell in a new writable project folder. .venv is a virtual environment folder, separate from source files. Do not create it over a folder already serving another purpose.
py -3 -m venv .venv
.\.venv\Scripts\python.exe -m pip --version
Check that pip’s path is under this project’s .venv. Directly invoking its Python avoids activation scripts and PowerShell execution-policy changes. This complete example installs and imports Colorama 0.4.6; substitute the dependencies and versions needed by your actual project.
.\.venv\Scripts\python.exe -m pip install "colorama==0.4.6"
.\.venv\Scripts\python.exe -c "import colorama, sys; print(colorama.__version__); print(sys.prefix != sys.base_prefix)"
After installation succeeds, the final command prints 0.4.6 and True on separate lines. True indicates a virtual environment. The workflow was checked on Windows with Python 3.12.14 and virtual-environment pip 25.0.1; detailed logs and paths vary by installation.
.\.venv\Scripts\python.exe -m pip show colorama
In pip show, check that Location is the project’s .venv\Lib\site-packages. An IDE may still select another Python even when terminal imports work. Set its project interpreter to the same .venv\Scripts\python.exe.
Use --user as an alternative outside virtual environments
A --user installation uses that Python’s user-package location instead of the global directory. It can suit a personal setup without project isolation, but does not separate package versions across projects. Identify the base interpreter first as above.
py -3 -m pip install --user "colorama==0.4.6"
This installs the sample into the base Python’s user location. Do not add it to the virtual-environment workflow. A normal isolated virtual environment rejects --user because its user site is not visible. If permissions still fail inside a virtual environment, investigate the actual failed path instead of adding this option.
If installation still fails or pip is missing
Read the last message before calling every failure a permissions issue. No matching distribution found, certificate, proxy, and network failures require package compatibility or connection checks. Follow the Python package installation guide to align interpreter and package requirements.
If the new environment reports No module named pip, repair its pip as follows. ensurepip prepares the pip bundled with Python; it does not necessarily update to the latest internet release.
.\.venv\Scripts\python.exe -m ensurepip --upgrade
.\.venv\Scripts\python.exe -m pip --version
If the base Python lacks ensurepip or environment creation keeps failing, examine the distribution’s components and paths. Close the relevant IDE or application normally if it is using the package files, then retry. For security-tool blocks, review the recorded event and permitted policy. Use administrator installation only where it is the intended managed deployment procedure.
Undo the example installation
To remove only the Colorama installed in this new example environment, use the following. -y skips confirmation, so verify the environment and package first.
.\.venv\Scripts\python.exe -m pip uninstall -y colorama
pip uninstall removes a package from the selected environment. An unneeded new environment can be removed after confirming it contains no source and is not used elsewhere. If you changed an existing project’s dependencies, restore its recorded required versions. Include the failed command, Python and pip paths, final error, and target path in a useful error report.




