when I use docker-compose to install a fastapi project, I got AssertionError: jinja2 must be installed to use Jinja2Templates
but when I use env to install it, that will be run well.
my OS:
Ubuntu18.04STL
my requirements.txt:
fastapi~=0.68.2
starlette==0.14.2
pydantic~=1.8.1
uvicorn~=0.12.3
SQLAlchemy~=1.4.23
# WSGI
Werkzeug==1.0.1
pyjwt~=1.7.0
# async-exit-stack~=1.0.1
# async-generator~=1.10
jinja2~=2.11.2
# assert aiofiles is not None, "'aiofiles' must be installed to use FileResponse"
aiofiles~=0.6.0
python-multipart~=0.0.5
requests~=2.25.0
pyyaml~=5.3.1
# html-builder==0.0.6
loguru~=0.5.3
apscheduler==3.7.0
pytest~=6.1.2
html2text==2020.1.16
mkdocs==1.2.1
Dockerfile
FROM python:3.8
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
WORKDIR /server
COPY requirements.txt /server/
RUN pip install -r requirements.txt
COPY . /server/
docker-compose.yml
version: '3.7'
services:
figbox_api:
build:
context: .
dockerfile: Dockerfile
command: uvicorn app.main:app --port 8773 --host 0.0.0.0 --reload
volumes:
- .:/server
ports:
- 8773:8773
Do I need to provide some other information?
Thanks
I had a same problem on heroku, the error comes from Jinja2 version 2.11.x and it run locally but not in Heroku.
Just install latest version of jinja2 it will work fine in your case too.
pip install Jinja2==3.1.2
or
pip install Jinja2 --upgrade
Have had same issue, using Jinja2 (without version annotation) solved it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With