Docker ModuleNotFoundError: No module named 'xhtml2pdf'
I've looked through several websites but I can't seem to find an answer. I'm new to django and docker and whilist building my first project which is a quotation generator, I've been looking for different ways to generate a pdf for each quote.
I found a couple of tutorials on xhtml2pdf and my error appears when I try to run
docker-compose up and get the following error:
ModuleNotFoundError: No module named 'xhtml2pdf'
I've installed xhtml2pdf using pip3 install xhtml2pdf
and whenever I try to run it again I get:
Requirement already satisfied: xhtml2pdf, the same for its dependencies.
I've also tried pip install --upgrade --force-reinstall xhtml2pdf with no luck
on my views.py file if I write from xhtml2pdf import pisa vs code gives me no errors regarding the import
My requirements.txt lookslike this:
psycopg2==2.9.1
pillow>=8.3
xhtml2pdf==0.2.5
reportlab==3.6.1
Dockerfile:
FROM python:3.8
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
WORKDIR /code
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
you have to build the image first after you added new packages in your requirements.txt to get them installed. Simply running docker-compose up will just run the image you previously built. Surely that image does not contain the new pip package xhtmltopdf
use
docker-compose build
then
docker-compose up
or you can use the following command to do it at once
docker-compose up --build
If you want to build the image entirely from scratch use
docker-compose build --no-cache