In the past days I found a weird error when I export a model created with CustomVision.ai to docker. The docker image build ok, however, I found this error when I try to run the container.
❯ docker run -p 8090:8090 squirrelscv Traceback (most recent call last): File "app.py", line 7, in <module> from flask import Flask, request, jsonify File "/usr/local/lib/python3.7/site-packages/flask/ __init__.py", line 14, in <module> from jinja2 import escape File "/usr/local/lib/python3.7/site-packages/jinja2/ __init__.py", line 12, in <module> from .environment import Environment File "/usr/local/lib/python3.7/site-packages/jinja2/environment.py", line 25, in <module> from .defaults import BLOCK_END_STRING File "/usr/local/lib/python3.7/site-packages/jinja2/defaults.py", line 3, in <module> from .filters import FILTERS as DEFAULT_FILTERS # noqa: F401 File "/usr/local/lib/python3.7/site-packages/jinja2/filters.py", line 13, in <module> from markupsafe import soft_unicode ImportError: cannot import name 'soft_unicode' from 'markupsafe' (/usr/local/lib/python3.7/site-packages/markupsafe/ __init__.py)
And hey, it took me sometime to understand and find a way to solve the error. If you want to avoid searching and reading, you only need to read this Issue
And hey, the solution is to make a downgrade to some packages in the docker image definition. The following docker definition, adds the 2 necessary packages to make it work.
FROM python:3.7-slim RUN pip install -U pip # custom packages version to avoid custom vision error RUN pip install markupsafe==2.0.1 RUN pip install protobuf==3.20.1 RUN pip install --no-cache-dir numpy~=1.17.5 tensorflow~=2.0.2 flask~=1.1.2 pillow~=7.2.0 RUN pip install --no-cache-dir mscviplib==2.200731.16 COPY app /app # Expose the port EXPOSE 8090 # Set the working directory WORKDIR /app # Run the flask server for the endpoints CMD python -u app.py
And, now we can run the images !
More posts in my blog ElBruno.com.