Home > Net >  Issues with flask 1,1.2 and 2.2.2
Issues with flask 1,1.2 and 2.2.2

Time:09-03

So I've been following along a course which deals with web services and I've encountered an issue with flask dependencies.

my requirements.txt looks like this:

PyMySQL==1.0.2
cryptography==37.0.4
Flask==2.2.2
flask_sqlalchemy==2.5.1
sqlalchemy < 1.4.0
flask_migrate==2.7.0
flask_script==2.0.6
sqlalchemy_utils==0.38.3

And my manage.py which I run with python manage.py db init looks like this

from flask import Flask
from flask_migrate import Migrate, MigrateCommand
from flask_script import Manager
from configuration import Configuration
from models import database
from sqlalchemy_utils import  database_exists, create_database

application = Flask(__name__)
application.config.from_object(Configuration)

migrate = Migrate(application, database)

manager = Manager(application)
manager.add_command('db', MigrateCommand)


if __name__ == '__main__':
    if(not database_exists(Configuration.SQLALCHEMY_DATABASE_URI)):
        create_database(Configuration.SQLALCHEMY_DATABASE_URI)
    manager.run()

When I use flask 2.2.2 I get this error:

Traceback (most recent call last):
  File "/home/remax/PycharmProjects/V3/manage.py", line 3, in <module>
    from flask_script import Manager
  File "/home/remax/PycharmProjects/V3/venv/lib/python3.10/site-packages/flask_script/__init__.py", line 15, in <module>
    from flask._compat import text_type
ModuleNotFoundError: No module named 'flask._compat'

But when I go back to flask 1.1.2 I get this ImportError: cannot import name 'escape' from 'jinja2'

I honestly don't know how to deal with this, I've been trying to find a solution all morning

CodePudding user response:

flask-script has been obsolete since Flask 0.11 added command support. It hasn't been updated to work with Flask 2, so if you want to use Flask 2, you'll need to get rid of it (and use Flask's native command support instead).

If you have upgraded Flask to 2.x and decide to downgrade to 1.x, you will need to install compatible versions of supporting packages (werkzeug, itsdangerous, jinja2). It might be easiest to just uninstall all packages from your virtualenv (you're using one, right?) and reinstall the correct versions, but you can also do it by hand.

  • Related