Mahmudul Hassan
Mahmudul Hassan

Reputation: 427

Pillow is not found by Django thouhg it is installed using docker

Hello I am following this tutorial tutorial link. Everything is working fine but when i run bellow command it says pillow is not found but pillow already is installed.

docker-compose -f docker-compose.prod.yml exec app python manage.py migrate --noinput

This is the error:

employee.Employee.image: (fields.E210) Cannot use ImageField because Pillow is not installed.
    HINT: Get Pillow at https://pypi.org/project/Pillow/ or run command "python -m pip install Pillow".
students.Student.image: (fields.E210) Cannot use ImageField because Pillow is not installed.
    HINT: Get Pillow at https://pypi.org/project/Pillow/ or run command "python -m pip install Pillow".

Then i again try to install using bellow command

docker-compose -f docker-compose.prod.yml exec app python -m pip install Pillow

And it says pillow is Pillow is already installed

Requirement already satisfied: Pillow in /usr/local/lib/python3.8/site-packages (6.2.1)

Here is my docker file

###########
# BUILDER #
###########

# pull official base image
FROM python:3.8.3-alpine as builder

# set work directory
WORKDIR /usr/src/app

# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# install psycopg2 dependencies
RUN apk update \
    && apk add postgresql-dev gcc python3-dev zlib-dev jpeg-dev musl-dev


# lint
RUN pip install --upgrade pip
RUN pip install Pillow
COPY . .


# install dependencies
COPY ./requirements.txt .
RUN pip wheel --no-cache-dir --no-deps --wheel-dir /usr/src/app/wheels -r requirements.txt


#########
# FINAL #
#########

# pull official base image
FROM python:3.8.3-alpine

# create directory for the app user
RUN mkdir -p /home/app

# create the app user
RUN addgroup -S app && adduser -S app -G app

# create the appropriate directories
ENV HOME=/home/app
ENV APP_HOME=/home/app/web
RUN mkdir $APP_HOME
RUN mkdir $APP_HOME/staticfiles
RUN mkdir $APP_HOME/mediafiles
WORKDIR $APP_HOME

# install dependencies
RUN apk update && apk add libpq
COPY --from=builder /usr/src/app/wheels /wheels
COPY --from=builder /usr/src/app/requirements.txt .
RUN pip install --no-cache /wheels/*

# copy entrypoint-prod.sh
COPY ./entrypoint.prod.sh $APP_HOME

# copy project
COPY . $APP_HOME

# chown all the files to the app user
RUN chown -R app:app $APP_HOME

# change to the app user
USER app

# run entrypoint.prod.sh
ENTRYPOINT ["/home/app/web/entrypoint.prod.sh"]

Please Help me .

Upvotes: 3

Views: 479

Answers (3)

Dmytro Zimin
Dmytro Zimin

Reputation: 31

I was stuck with the same problem. Adding these dependencies to the FINAL section resolved this issue

# install pillow dependencies
RUN apk add --no-cache jpeg-dev zlib-dev \
    fribidi-dev \
    harfbuzz-dev \
    lcms2-dev \
    openjpeg-dev \
    tcl-dev \
    tiff-dev \
    tk-dev 

Upvotes: 0

Basil C Sunny
Basil C Sunny

Reputation: 424

Add this two lines under the FINAL section, just below the RUN apk update && apk add libpq

# install pillow dependencies
RUN apk add --no-cache jpeg-dev zlib-dev
RUN apk add --no-cache --virtual .build-deps build-base linux-headers

This is happening because the BUILDER removes the dependencies required for Pillow after creating the image. In the FINAL image, Pillow is available, but its required dependencies are not.

Upvotes: 1

Andrey Borzenko
Andrey Borzenko

Reputation: 738

Please try to use "pillow" starting from lowercase p.

Upvotes: 1

Related Questions