noahgift / flask-ml-azure-serverless

Deploy Flask Machine Learning Application on Azure App Services
99 stars 199 forks source link

ImportError: cannot import name 'Markup' from 'jinja2' #5

Closed rb-mwindh closed 1 year ago

rb-mwindh commented 1 year ago

I'm all new to python, currently attending a course on machine learning. I've followed your instructions "by-the-letter", but when I run python app.py I get the following error message:

$ python app.py
Traceback (most recent call last):
  File "app.py", line 1, in <module>
    from flask import Flask, request, jsonify
  File "/home/testuser/.flask-ml-azure/lib/python3.8/site-packages/flask/__init__.py", line 19, in <module>
    from jinja2 import Markup, escape
ImportError: cannot import name 'Markup' from 'jinja2' (/home/testuser/.flask-ml-azure/lib/python3.8/site-packages/jinja2/__init__.py)

Environment:

$ pip freeze
astroid==2.4.2
click==8.1.3
Flask==1.0.2
isort==5.10.1
itsdangerous==2.1.2
Jinja2==3.1.2
joblib==1.2.0
lazy-object-proxy==1.4.3
MarkupSafe==2.1.1
mccabe==0.6.1
numpy==1.23.5
pandas==1.1.5
pkg_resources==0.0.0
pylint==2.6.2
python-dateutil==2.8.2
pytz==2022.6
scikit-learn==0.22.2
scipy==1.9.3
six==1.16.0
toml==0.10.2
Werkzeug==2.2.2
wrapt==1.14.1

Can you please help me getting your sample app up-and-running?

Thanks ;)

rb-mwindh commented 1 year ago

I've updated Flask to the current release (2.2.2 at the time being), by changing the requirements.txt file:

// requirements.txt
Flask==2.2.2
pandas==1.1.5
scikit-learn==0.22.2
pylint==2.6.2
$ make install
$ python app.py
/home/testuser/.flask-ml-azure/lib/python3.8/site-packages/sklearn/externals/joblib/__init__.py:15: FutureWarning: sklearn.externals.joblib is deprecated in 0.21 and will be removed in 0.23. Please import this functionality directly from joblib, which can be installed with: pip install joblib. If this warning is raised when loading pickled models, you may need to re-serialize those models with scikit-learn 0.21+.
  warnings.warn(msg, category=FutureWarning)
 * Serving Flask app 'app'
 * Debug mode: on
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
 * Running on all addresses (0.0.0.0)
 * Running on http://127.0.0.1:5000
 * Running on http://192.168.67.3:5000
Press CTRL+C to quit
 * Restarting with stat
/home/testuser/.flask-ml-azure/lib/python3.8/site-packages/sklearn/externals/joblib/__init__.py:15: FutureWarning: sklearn.externals.joblib is deprecated in 0.21 and will be removed in 0.23. Please import this functionality directly from joblib, which can be installed with: pip install joblib. If this warning is raised when loading pickled models, you may need to re-serialize those models with scikit-learn 0.21+.
  warnings.warn(msg, category=FutureWarning)
 * Debugger is active!
 * Debugger PIN: 123-456-789

I'm trying to get rid of the warning as well...

rb-mwindh commented 1 year ago

According to pip freeze, my workspace is running with joblib==1.2.0. So I changed

// app.py
from flask import Flask, request, jsonify
from flask.logging import create_logger
import logging

import pandas as pd
# from sklearn.externals import joblib
import joblib
...

This solved the deprecation warning. I'm back on track, sorry for disturbing ;)