Replit-py not compatible with Flask 3.0.0 in Python

Has anyone run into an issue where they cannot import the latest version of Flask and Replit. When I try to import flask I get this error:

Because replit (3.3.2) depends on Flask (>=2.0.0,<3.0.0)
and no versions of replit match >3.3.2,<4.0.0, replit (>=3.3.2,<4.0.0) requires Flask (>=2.0.0,<3.0.0).
So, because python-template depends on both replit (^3.3.2) and flask (^3.0.0), version solving failed.
exit status 1

I’ve tried installing a previous version of flask but then when I try and start the server with this code:

from replit import web, db
from flask import Flask
app = Flask(__name__)
web.run(app)

I get the following error:

Traceback (most recent call last):
File "/home/runner/IntrepidAltruisticMultiprocessing/main.py", line 6, in <module>
  replit.web.run(app)
File "/home/runner/IntrepidAltruisticMultiprocessing/.pythonlibs/lib/python3.10/site-packages/replit/web/app.py", line 62, in run
   if change_encoder and app.json_encoder is flask.json.JSONEncoder:
AttributeError: 'Flask' object has no attribute 'json_encoder'

Any help would be much appreciated!

Downgrade flask: run in Shell:

poetry add 'Flask@>=2.0,<2.3'

Alternatively, create a PR/issue on GitHub - replit/replit-py: A helpful Python package that helps you build excellent things inside Repls! 💻 to support Flask 2.3.3 (and, if possible, 3.0).

3 Likes

Thanks that resolved the issue. I’m surprised no-one has reported this previously, with the amount of users replit has I thought someone would have encountered this problem before as using flask and replit-py is a very common setup.

1 Like

Yeah I have encountered this before. My solution? Keep Flask’s version the way it is and don’t use the replit module to run the app.

app.run('0.0.0.0')
3 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.