Could not install packages due to an EnvironmentError Errno 13
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
EnvironmentError: [Errno 13] Permission denied during pip install almost always means pip is trying to write to a location your current user cannot modify. The fix is usually not “run everything as administrator.” The real fix is to install into the right environment, with the right ownership, using the right Python interpreter.
What Errno 13 Usually Means
When pip installs a package, it needs to create directories, copy files, and update metadata under the target site-packages path. If that target path belongs to the system Python or another user, the install fails.
You can confirm which Python and pip you are using with:
Those commands tell you whether the installation is targeting a global interpreter, a virtual environment, or a different Python than you expected.
The Best Default Fix: Use a Virtual Environment
For application development, a virtual environment is the cleanest solution because it gives your project its own writable package directory.
Inside the activated environment, pip writes to .venv instead of the system Python directories. That avoids most permission problems and keeps project dependencies isolated.
If the environment is active but pip still resolves to a global interpreter, prefer python -m pip instead of bare pip. That forces pip to run under the interpreter you selected.
Use --user for Per-User Installs
If you are not working inside a project environment and just need a package for your own account, --user is often enough.
This installs into your user site-packages directory rather than a system-managed path. It is a reasonable option for standalone tools, although virtual environments are still the better choice for project-specific dependencies.
One caveat is that scripts installed under the user site path may require updating your PATH so the commands are discoverable.
Avoid sudo pip install in Normal Development
Using sudo can make the immediate error disappear, but it often creates a mess later. Packages may end up owned by root, upgrades become inconsistent, and the global interpreter can drift away from what your projects expect.
A safer rule is:
- use a virtual environment for project work
- use
--userfor personal tools - use the system package manager only when you truly want a system-wide package
That separation reduces both permission issues and environment confusion.
Watch for File Ownership Problems
Sometimes the error appears even inside a virtual environment because part of the environment was created or modified by another user account. That can happen after mixing sudo, CI artifacts, or copied directories.
Check ownership of the target directory:
If the environment contains files owned by a different user, the practical fix is usually to remove and recreate the virtual environment rather than trying to patch every file permission by hand.
Windows and Managed Python Installs
On Windows, the same error can come from installing under a protected directory such as Program Files, or from a Python interpreter managed by the Microsoft Store, enterprise policy, or antivirus software. The same principles still apply:
- confirm which interpreter is active
- prefer a virtual environment
- avoid global installs unless you actually need them
Using the Python launcher makes interpreter selection clearer:
Common Pitfalls
- Running
pip installagainst the system Python when you meant to use a project virtual environment. - Using bare
pipand assuming it belongs to the same interpreter aspython. - Fixing the symptom with
sudoand then creating root-owned packages that break future installs. - Ignoring file ownership problems inside an existing environment after mixing users or tools.
- Installing personal tools globally when
--useror an isolated environment would be safer.
Summary
- Errno 13 during
pip installmeans the target location is not writable by the current user. - The most reliable fix is to install packages inside a virtual environment.
- '
python -m pipis safer than barepipwhen multiple interpreters are present.' - '
--useris a practical fallback for per-user tools outside project environments.' - Avoid
sudo pip installunless you deliberately want system-wide changes and understand the ownership consequences.

