Gunicorn Command Not Found, But It's in My Requirements.Txt

gunicorn command not found, but it's in my requirements.txt

I also have Pipfile and Pipfile.lock files

That's your problem: you're using two different tools that, partly, do the same thing.

If you have a Pipfile and Pipfile.lock, Heroku uses Pipenv to install your dependencies, and your requirements.txt will be ignored.

In the absence of a Pipfile and Pipfile.lock, Heroku uses pip to install dependencies from requirements.txt.

Pick a single tool and use it everywhere. If you choose Pipenv, make sure all of your dependencies are reflected in your Pipfile and Pipfile.lock (e.g. by running pipenv install -r requirements.txt), delete your requirements.txt, and redeploy. If you want to use pip, get rid of your Pipfile and Pipfile.lock.

gunicorn: command not found

You should RUN pip install as root, without the --user option.

If you run pip install --user, it installs packages into ~/.local. In Docker the $HOME environment variable isn't usually defined, so this will install them into /.local. If you looked inside the built image, you'd probably find a runnable /.local/bin/gunicorn, but that /.local/bin directory isn't on the $PATH.

Typical use in Docker is to install Python packages into the "system" Python; the Docker image itself is isolation from other Pythons. This will put the *.py files into somewhere like /usr/local/lib/python3.10/site-packages, and the gunicorn executable will be in /usr/local/bin, which is on the standard $PATH.

FROM python:3.10.5-alpine
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
RUN adduser -D appuser
WORKDIR /home/appuser/
# but do not change USER yet

COPY --chown=appuser:appuser requirements.txt .

# Without --user option
RUN python -m pip install --no-cache-dir --disable-pip-version-check --requirement requirements.txt

# Change USER _after_ RUN pip install
USER appuser

COPY --chown=appuser:appuser . .
ENTRYPOINT [ "./entrypoint.sh" ]

Heroku + gunicorn not working (bash: gunicorn: command not found )

The issue seemed to fix itself after uninstalling all requirements remotely, and reinstalling them.



Related Topics



Leave a reply



Submit