Introducing Livops 2.0! Promo codeCEOgives you 8,000 so‘m on your balance.What’s new

ERROR: Could not install packages due to an OSError (pip): Errno 13, 28 and 2 fixed

ERROR: Could not install packages due to an OSError means the operating system refused a file operation while pip was installing, and the text after the colon says which: [Errno 13] Permission denied is a folder pip may not write to, usually a system Python or a root-owned environment; [Errno 28] No space left on device is a full disk or temp folder; [Errno 2] No such file or directory on Windows is often a path over 260 characters. Install into a virtual environment, free space or point TMPDIR elsewhere, and enable long paths; never sudo pip.

By Livops team, the people who build and run LivopsUpdated

pip prints this when the operating system refuses a file operation during pip install. The first part is pip’s sentence, the part after the colon is the error it got, and on a permission error pip adds a hint line[1][2]. Three versions of it, as pip formats them (the paths are examples):

ERROR: Could not install packages due to an OSError: [Errno 13] Permission denied: '/usr/local/lib/python3.12/site-packages/requests'
Consider using the `--user` option or check the permissions.
ERROR: Could not install packages due to an OSError: [Errno 28] No space left on device
ERROR: Could not install packages due to an OSError: [Errno 2] No such file or directory: 'C:\\Users\\me\\project\\.venv\\Lib\\site-packages\\...'
HINT: This error might have occurred since this system does not have Windows Long Path support enabled. You can find information on how to enable this at https://pip.pypa.io/warnings/enable-long-paths

They are one error with different causes. This page reads the part after the colon, gives the fix for each, and says what Livops does.

What does the error mean?

pip wraps the whole install in one handler: any OSError raised while it resolves, downloads, builds or installs packages ends the command with Could not install packages due to an OSError, followed by the error itself[1]. pip’s logger puts ERROR: in front[2]. With -v, pip prints the traceback instead of the one-line error, which shows exactly which file was refused[1]:

python -m pip install -v -r requirements.txt

The text in brackets is Python’s name for the operating system’s error. The three you will meet[10]:

In the message Python’s name What happened
[Errno 13] Permission denied errno.EACCES pip may not write or remove a file at that path
[Errno 28] No space left on device errno.ENOSPC the disk, or the temporary folder, is full
[Errno 2] No such file or directory errno.ENOENT a path pip needed does not exist, or Windows could not resolve it

Two of pip’s hint lines matter here. For Permission denied, outside a virtual environment and without --user, it suggests the --user option or checking permissions; inside a virtual environment or with --user, only checking permissions[1]. On Windows, for ENOENT and EINVAL errors with a path longer than 260 characters, or a single name longer than 255, it adds a HINT about long paths[1].

[Errno 13] Permission denied

Cause: installing into a Python that belongs to root

The usual case is pip install into a system-wide Python, /usr/lib/python3/... or /usr/local/lib/python3.X/site-packages, as a normal user. pip checks this in advance: if you did not ask for --user or against it, and it finds the site-packages folders not writable, it prints Defaulting to user installation because normal site-packages is not writeable and installs into your home directory instead[1]. So you see the error when that check passes but a file inside does not:

  • A package installed earlier with sudo pip. pip tests only that the site-packages folders are writable[1]. A package that sudo put there belongs to root, so upgrading or removing it as yourself fails on its files.
  • A virtual environment created with sudo. Inside a virtual environment pip does not fall back to --user, and its hint says only Check the permissions[1]. If root created the environment, its folders belong to root, and your pip install cannot write there.
  • User installs switched off. When user site-packages are disabled for this Python, by -s, PYTHONNOUSERSITE or for security reasons, pip does not fall back to them either[1][12].

Fix: use a virtual environment you own

Make the environment as yourself, in the project folder, and install with its own Python:

python3 -m venv .venv
.venv/bin/python -m pip install -r requirements.txt
.venv/bin/python main.py

You do not have to activate it: running the environment’s Python by its full path is enough, and scripts installed into it run without activating[8]. If the existing .venv was made by root, delete it and create it again; a virtual environment is meant to be disposable and recreated, not moved or repaired[8]:

sudo rm -rf .venv
python3 -m venv .venv

Do not fix it with sudo

sudo pip install makes the error go away once and causes the next one: everything it writes belongs to root. pip warns about this itself when it runs as root outside a virtual environment: running pip as the root user “can result in broken permissions” and conflicts with the system package manager, and a virtual environment is recommended instead[3].

Where –user fits

pip install --user installs into the user scheme instead of the system folders[5], under site.USER_BASE, which is ~/.local on Linux[12]. It is a fix on your own machine with a Python that allows it, not in general:

  • In a default virtual environment pip refuses --user outright, because the user site is not on that environment’s path[5][1].
  • A Python marked externally managed checks the marker for --user installs too[1] and refuses with a different error; see externally-managed-environment.

A virtual environment works in all of these cases, which is why it is the first fix.

[Errno 28] No space left on device

Cause: a full disk, a full temporary folder, or pip’s cache

pip builds packages, and the build environments they need, in temporary folders it creates with Python’s tempfile.mkdtemp[4]. Python puts those in the folder named by TMPDIR, TEMP or TMP, and otherwise in /tmp, /var/tmp or /usr/tmp on Linux and macOS[9]. So a small /tmp can fill up even when the main disk has room.

pip also keeps a cache of downloads and built wheels, on by default, in ~/.cache/pip on Linux, ~/Library/Caches/pip on macOS and %LocalAppData%\pip\Cache on Windows[6]. On a small server or a CI runner it grows over time.

Fix: find the full disk, then free it or move pip

df -h                       # which disk is full: / or /tmp?
python -m pip cache info    # how big pip's cache is, and where
python -m pip cache purge   # empty it

pip cache info shows the total size and location of the cache, and pip cache purge clears all files from pip’s wheel and HTTP caches[6]. To install without writing to the cache at all, add --no-cache-dir, or set PIP_NO_CACHE_DIR[7]. pip’s docs advise this mainly where something else caches, such as layered container builds, as it can make pip much slower[6]:

python -m pip install --no-cache-dir -r requirements.txt

If /tmp is what is full, point the temporary folder at a disk with room for that one command[9], and move the cache with --cache-dir (PIP_CACHE_DIR) the same way[7]:

mkdir -p "$HOME/pip-tmp"
TMPDIR="$HOME/pip-tmp" python -m pip install -r requirements.txt

In a Dockerfile, RUN pip install --no-cache-dir -r requirements.txt keeps the cache out of the image layer.

[Errno 2] No such file or directory

Cause on Windows: a path over 260 characters

Windows has historically limited paths to 260 characters, and longer paths do not resolve[11]. A virtual environment deep in a user folder, plus a package with deeply nested files, can pass that. pip spots this and adds a HINT line: for a full path over 260 characters, that long path support is not enabled; for a single file or folder name over 255 characters, that this is a Windows limit even with long paths enabled[1].

Fix: enable long paths, or shorten the path

An administrator enables the “Enable Win32 long paths” group policy, or sets LongPathsEnabled to 1 under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem; after a reboot, Python accepts paths longer than 260 characters[11]. Without admin rights, make the path short instead, by creating the environment near the root of a drive:

py -m venv C:\venvs\myapp
C:\venvs\myapp\Scripts\python -m pip install -r requirements.txt

The 255-character limit on a single name stays even with long paths on[1]; then the package itself has to change.

Cause elsewhere: a file that is gone

On Linux and macOS, [Errno 2] with a path means a file pip expected was not there. Run with -v to see which file and which step[1]. If the path is inside a virtual environment that was copied or moved from another folder, recreate it where it runs: environments are not meant to be moved or copied[8].

How to confirm the fix locally

Check which Python and pip you are using, and that you are in a virtual environment:

.venv/bin/python -m pip --version
.venv/bin/python -c 'import sys; print(sys.prefix != sys.base_prefix)'

The first line names a path inside .venv; the second prints True in a virtual environment[8]. Then run the install again. If it now fails while compiling a package, see Failed building wheel.

On Livops

  • You do not install into a system Python. Livops installs your dependencies itself, and commands run from the project’s .venv: a start command reads .venv/bin/python main.py, and a Procfile line worker: .venv/bin/python bot.py. No sudo, no --user.

  • Do not upload your .venv. When you upload a folder, venv and .venv are dropped automatically.

  • List packages in requirements.txt, do not install them from running code. While an app or bot runs, its code folder is read-only, and /tmp is wiped on every restart and deploy and holds 128 MB. /app/data (the DATA_DIR variable) is the project’s disk for data, not for packages. See Files and data.

  • When an install fails, the deploy stops as install_failed, pip’s output is in the build log with a Tip: line at its end, and the old version keeps running. The assistant explains the log next to the failed build.

  • Your own install command. Settings → Install, or "install" in livops.json, holds the command that installs dependencies. If you change it, leave sudo and --user out.

  • Choose the Python. Livops runs Python 3.10 to 3.14; a .python-version file at the project root pins it, for example 3.12.

A Python web app costs 39 credits a month; a bot, worker or cron job 19. The install errors Livops recognises are in Install failed.

Questions

What does Could not install packages due to an OSError mean?

pip asked the operating system to create, write or remove a file during the install, and the operating system said no. pip prints its own sentence and then the error it got, such as [Errno 13] Permission denied, [Errno 28] No space left on device or [Errno 2] No such file or directory. The fix depends on that part.

Should I run sudo pip install to fix Permission denied?

No. pip itself warns that running it as root can result in broken permissions and conflicts with the system package manager, and recommends a virtual environment instead. Files sudo writes stay owned by root, which causes the next Permission denied.

Is pip install --user the right fix?

Sometimes, on your own machine with a Python that allows it: --user installs into your home directory instead of the system folders. It does not work inside a normal virtual environment, where pip refuses --user, and a Python marked externally managed refuses it too. A virtual environment is the fix that works everywhere.

How do I fix Errno 28 No space left on device during pip install?

Free space on the disk that is full. pip builds in a temporary folder, by default /tmp on Linux, and keeps a cache, by default ~/.cache/pip. Clear the cache with pip cache purge, install with --no-cache-dir, or set TMPDIR to a folder on a bigger disk for that command.

Why does pip say No such file or directory for a file that should exist on Windows?

Often the full path is over 260 characters, the old Windows limit. pip adds a HINT line when it sees that, and the fix is to enable long paths in Windows, or to put the virtual environment in a short folder such as C:\venvs\app.

How do I see the full error?

Run the same command with -v. pip then prints the traceback with the message, which shows the exact file the operating system refused.

Does this happen on Livops?

Livops installs your dependencies itself into the project's .venv, so you do not choose where packages go or run sudo. If an install fails, the deploy stops as install_failed, pip's output is in the build log, and the previous version keeps running.

Sources

  1. pip source — src/pip/_internal/commands/install.py (create_os_error_message, decide_user_install) (raw.githubusercontent.com). Checked .
  2. pip source — src/pip/_internal/utils/logging.py (raw.githubusercontent.com). Checked .
  3. pip source — src/pip/_internal/utils/misc.py (warn_if_run_as_root) (raw.githubusercontent.com). Checked .
  4. pip source — src/pip/_internal/utils/temp_dir.py (raw.githubusercontent.com). Checked .
  5. pip docs — User Guide, User Installs (pip.pypa.io). Checked .
  6. pip docs — Caching (pip.pypa.io). Checked .
  7. pip docs — pip (general options) (pip.pypa.io). Checked .
  8. Python docs — venv (docs.python.org). Checked .
  9. Python docs — tempfile (docs.python.org). Checked .
  10. Python docs — errno (docs.python.org). Checked .
  11. Python docs — Using Python on Windows, Removing the MAX_PATH limitation (docs.python.org). Checked .
  12. Python docs — site (docs.python.org). Checked .

Put your project online today

Connect GitHub or drop a folder. No card is asked for.

Deploy your Python app

Got a question? — @livops_uz