# gunicorn: command not found (or uvicorn: command not found): how to fix it

> gunicorn: command not found, uvicorn: command not found and gunicorn: not found mean the shell looked for the command on PATH and did not find it, so the start ends with exit code 127. Gunicorn or Uvicorn is not in requirements.txt, or it was installed into a virtual environment or a --user folder whose bin is not on PATH. Add it to requirements.txt and start it through the environment's own Python: .venv/bin/python -m gunicorn or .venv/bin/python -m uvicorn.

Source: https://livops.dev/en/guides/error-gunicorn-command-not-found

By Livops team, the people who build and run Livops. Updated 1 December 2026.

What the log shows when the start command cannot find the server (the shell's wording varies):

```text
bash: line 1: gunicorn: command not found
```

```text
/bin/sh: 1: uvicorn: not found
```

and then the process ends with exit code 127. Nothing of your code has run yet: the shell never found the program. This page explains where the `gunicorn` and `uvicorn` commands come from, the four reasons the shell does not find them, and why `python -m gunicorn` and `python -m uvicorn` avoid the question altogether.

## What does the error mean?

Bash returns 127 when a command is not found, and 126 when it is found but cannot be executed[1]. A bare `gunicorn` is looked up in the folders on `PATH`; none of them has a file of that name.

That file is a small script that pip writes when it installs the package. Gunicorn declares it as `gunicorn = "gunicorn.app.wsgiapp:run"`[11], and Uvicorn as `uvicorn = "uvicorn.main:main"`[16]; Gunicorn's docs put it simply: after installation you have access to the `gunicorn` executable[8]. Where the script lands depends on where the package went:

| Installed with | The `gunicorn` script lands in | On `PATH` by itself? |
| --- | --- | --- |
| pip inside a virtual environment | `<venv>/bin` (`Scripts` on Windows)[2] | Only while the environment is activated[2] |
| `pip install --user` | `<userbase>/bin`[5], `~/.local/bin` on Linux[4] | Only if you added it |
| Nothing: not in `requirements.txt` | nowhere | — |

So "command not found" means one of two things: the package is not installed in the environment the server built, or it is installed into a `bin` folder the start command does not look in.

Two quick checks, run in the same place and the same way as the start command:

```sh
command -v gunicorn            # prints the path, or nothing
.venv/bin/python -c "import gunicorn"   # is it in the environment at all? (or uvicorn)
```

If the import fails, it is cause 1. If the import works but `command -v` prints nothing, it is cause 2 or 3.

## Causes, most common first

### 1. It is not in requirements.txt

You ran `pip install gunicorn` once on your laptop, and it is still there. The server installs only what `requirements.txt` lists, so on the server neither the package nor its script exists. This is the usual cause when the same command works locally.

**Fix:** list the server itself, not only the libraries your code imports:

```text
# requirements.txt
flask
gunicorn
```

```text
# requirements.txt, for FastAPI
fastapi
uvicorn[standard]
```

Uvicorn's install page gives both `uvicorn` and `uvicorn[standard]`[12]. If you run Gunicorn with Uvicorn workers, Gunicorn goes in too, since `gunicorn` is the command that starts, and so does the worker: Uvicorn's docs now point to the separate `uvicorn-worker` package for it[14].

### 2. The virtual environment is not activated

`source .venv/bin/activate` puts the environment's `bin` folder at the front of `PATH`, so `python` and the installed scripts are found without their full path[2]. It changes `PATH` in the shell where you ran it, and nowhere else. A systemd unit, a Supervisor program, a Docker `CMD` or a platform's start command starts a new process that never ran `activate`, so a bare `gunicorn` is looked up on the system's `PATH` and not found.

**Fix:** you do not need to activate anything. The Python docs: you can call the environment's interpreter by its full path, and all scripts installed in the environment should run without activating it, because their first line points to the environment's own Python[2]:

```sh
.venv/bin/gunicorn app:app --bind 0.0.0.0:8000
.venv/bin/uvicorn main:app --host 0.0.0.0 --port 8000
```

Uvicorn's own Supervisor example is written this way, as `venv/bin/uvicorn`[14]. Gunicorn's docs recommend installing it inside a virtual environment in the first place[7].

### 3. It was installed with --user, or by another user

`pip install --user` installs for the current user only[3], into the user scheme under `site.USER_BASE`, with scripts in `<userbase>/bin`[5]. On Linux `USER_BASE` defaults to `~/.local`[4], and `~/.local/bin` is often not on a server's `PATH`. The same happens when a Dockerfile installs as one user and the container runs as another: the scripts are in the first user's home.

**Fix:** install into a virtual environment instead, or start through the interpreter (below), which does not need the script at all.

### 4. pip belongs to another Python

`pip` on `PATH` may belong to another interpreter than the `python` that runs the app: the system Python, a second version, or a pyenv shim. The package is then installed, but for the wrong one. The Python docs recommend the versioned interpreter with `-m` to run the appropriate copy of pip[3]:

```sh
python3.12 -m pip install -r requirements.txt
```

Install and start with the same interpreter, and the question disappears.

### A virtual environment copied from another machine

A `.venv` folder committed to Git or copied from a laptop is not a fix. Scripts in it carry absolute paths to the interpreter that created them, so environments are not portable, and the Python docs say not to check them into source control[2]. Recreate it where it runs.

## The robust start command: python -m

Both servers can be started as a module of the interpreter that has them:

```sh
python -m gunicorn app:app
python -m uvicorn main:app
```

Gunicorn ships a `__main__.py` that runs the same function as the `gunicorn` script[10][11], and Uvicorn's `__main__.py` calls the same `main` as the `uvicorn` script[15][16]. With `-m`, Python locates the module with the standard import mechanism and runs it as `__main__`[6]. Three things follow:

- **No `PATH` lookup for the server.** Only `python` itself has to be found, and you can name it by path: `.venv/bin/python -m gunicorn`.
- **The right packages.** The server is imported from the same interpreter, so it sees the same installed libraries as your app.
- **A clearer error.** If the package really is missing, you get `No module named gunicorn` instead of a 127, which points straight to `requirements.txt`.

`-m` also puts the current directory at the start of `sys.path`[6], so run it from the folder that holds your app module.

Two settings to give either way. Gunicorn binds to `127.0.0.1:8000` by default, or to `0.0.0.0:$PORT` when the `PORT` variable is defined[9]; Uvicorn binds to `127.0.0.1` and port `8000` unless you pass `--host` and `--port`[13]. The app argument is `module:variable` for both[8][13]:

```sh
.venv/bin/python -m gunicorn app:app --bind 0.0.0.0:$PORT
.venv/bin/python -m uvicorn main:app --host 0.0.0.0 --port $PORT
```

## How to confirm the fix locally

Build a fresh environment from `requirements.txt` alone, the way a server does, and start through it without activating it:

```sh
python3 -m venv /tmp/check-env
/tmp/check-env/bin/python -m pip install -r requirements.txt
/tmp/check-env/bin/python -m gunicorn --version
/tmp/check-env/bin/python -m uvicorn --help
```

`python -m venv <dir>` is how the Python docs create an environment[2], and `gunicorn --version` is the check Gunicorn's install page gives[7]. If a line fails with `No module named`, the package is missing from `requirements.txt`. If all of them pass, start the app the same way, with your real start command.

## On Livops

- **Dependencies come from requirements.txt.** Livops installs them itself, and a `venv` or `.venv` folder in an uploaded project is dropped, so a package you installed only on your laptop is not there. Put `gunicorn` or `uvicorn` in `requirements.txt`. If the install itself fails, the deploy ends as `install_failed` and the build log has the error.
- **Write the environment into the start command.** The docs write Python start commands with the project's `.venv`, such as `.venv/bin/python main.py`. A server started the same way:

  ```text
  web: .venv/bin/python -m gunicorn app:app --bind 0.0.0.0:$PORT
  ```

  or, for FastAPI, `.venv/bin/python -m uvicorn main:app --host 0.0.0.0 --port $PORT`. A web app must listen on `0.0.0.0` and the port in `PORT`. Put the command in **Settings → Start**, or as a `web:` line in a `Procfile` at the project root (`worker:` is for a bot).
- **When it fails.** The deploy ends as `start_failed`, and the **Logs** page shows the app's last words, the `command not found` line among them, often with a **Tip:** line under it. A web app's previous version keeps running. See [The app did not start](https://livops.dev/en/docs/error-start).

Once the server starts, the next errors are inside it: [Gunicorn: Worker failed to boot](https://livops.dev/en/guides/error-gunicorn-worker-failed-to-boot), [Could not import module "main"](https://livops.dev/en/guides/error-uvicorn-could-not-import-module), or a library missing from `requirements.txt`, in [ModuleNotFoundError: No module named](https://livops.dev/en/guides/error-module-not-found-python).

## Questions

**What does exit code 127 mean?**

The shell could not find the command. Bash returns 127 when a command is not found, and 126 when it is found but cannot be executed. For gunicorn or uvicorn it means no folder on PATH holds a script with that name.

**Gunicorn is installed, so why is the command not found?**

It is installed somewhere the start command does not look: inside a virtual environment that is not activated, or in the per-user folder that pip --user uses, such as ~/.local/bin on Linux. Call it by its full path, or start it with the same environment's python -m gunicorn.

**Is python -m gunicorn the same as the gunicorn command?**

Yes. Gunicorn ships a __main__.py that runs the same function as the gunicorn script, and Uvicorn's __main__.py calls the same main function as the uvicorn script. The difference is that python -m finds the package through the Python you name, not through PATH.

**Do I need to activate the virtual environment in the start command?**

No. Activating only puts the environment's bin folder at the front of PATH. The Python docs say you can call the environment's interpreter by its full path, and that scripts installed in it run without activation.

**Does gunicorn need to be in requirements.txt if I use Uvicorn workers?**

Yes. Gunicorn is the command that starts, so it must be installed, and the worker class must be installed too; Uvicorn's docs now recommend the separate uvicorn-worker package for it. Put every program the start command calls into requirements.txt, not only the libraries your code imports.

**Can I just commit my local venv?**

No. The Python docs say a virtual environment should not be checked into source control and cannot be moved: its scripts hold absolute paths to the interpreter that created it. Commit requirements.txt and let the server build its own environment.

**What start command should a Python web app use on Livops?**

One that names the project's environment, the way the Livops docs write Python commands: for example .venv/bin/python -m gunicorn app:app or .venv/bin/python -m uvicorn main:app --host 0.0.0.0 --port $PORT. Put it in Settings, under Start, or as a web line in a Procfile.

## Sources

1. [GNU Bash manual — Exit Status](https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html). Checked 1 December 2026.
2. [Python docs — venv, creation of virtual environments](https://docs.python.org/3/library/venv.html). Checked 1 December 2026.
3. [Python docs — Installing Python modules](https://docs.python.org/3/installing/index.html). Checked 1 December 2026.
4. [Python docs — site, site-specific configuration hook](https://docs.python.org/3/library/site.html). Checked 1 December 2026.
5. [Python docs — sysconfig, installation paths](https://docs.python.org/3/library/sysconfig.html). Checked 1 December 2026.
6. [Python docs — Command line and environment](https://docs.python.org/3/using/cmdline.html). Checked 1 December 2026.
7. [Gunicorn docs — Installation](https://gunicorn.org/install/). Checked 1 December 2026.
8. [Gunicorn docs — Running Gunicorn](https://gunicorn.org/run/). Checked 1 December 2026.
9. [Gunicorn docs — Settings](https://gunicorn.org/reference/settings/). Checked 1 December 2026.
10. [Gunicorn source — gunicorn/__main__.py](https://github.com/benoitc/gunicorn/blob/master/gunicorn/__main__.py). Checked 1 December 2026.
11. [Gunicorn source — pyproject.toml](https://github.com/benoitc/gunicorn/blob/master/pyproject.toml). Checked 1 December 2026.
12. [Uvicorn docs — Installation](https://uvicorn.dev/installation/). Checked 1 December 2026.
13. [Uvicorn docs — Settings](https://uvicorn.dev/settings/). Checked 1 December 2026.
14. [Uvicorn docs — Deployment](https://uvicorn.dev/deployment/). Checked 1 December 2026.
15. [Uvicorn source — uvicorn/__main__.py](https://github.com/Kludex/uvicorn/blob/main/uvicorn/__main__.py). Checked 1 December 2026.
16. [Uvicorn source — pyproject.toml](https://github.com/Kludex/uvicorn/blob/main/pyproject.toml). Checked 1 December 2026.
