Skip to content
← Back to Community
Flask/Replit.web import errors and how to fix them.
Profile icon

Error when importing Flask and replit DB

Seeing this when importing both Flask and replit DB?

replit (3.0.0) depends on flask (>=1.1.2,<2.0.0) and no versions of replit match >3.0.0,<4.0.0, replit (>=3.0.0,<4.0.0) requires flask (>=1.1.2,<2.0.0). So, because repl-python3-bot depends on both replit (^3.0.0) and flask (^2.0.0), version solving failed. exit status 1

That's because the replit package includes it's own Flask fork that conflicts with Flask. Instead of using from flask import Flask use from replit.web import App and use app = App(__name__) instead of app = Flask(__name__). This flask fork adds a few new features like login with replit for your site. See its docs here

Error when trying to import Response from replit.web

You might've run into this when trying to do things like specifying MIME types in your template renders. In Flask, you could fix them like this:
Response("Response CSS", mimetype="text/css")

However that doesn't work in replit.web. There is a workaround, however:

  1. Add flask = "^1.1.2" to pyproject.toml under [tool.poetry.dependencies]
  2. Use from flask import Response in your code.

Error attempting to use replit.web on a thread other than the main thread

You cannot multithread replit.web, so we must use a version of Flask that is compatible with the replit module.

  1. Add flask = "^1.1.2" to pyproject.toml under [tool.poetry.dependencies]
  2. Use from flask import Flask in your code instead of from replit.web import App, app = Flask(__name__) instead of app = App(__name__) and"") instead of You should now be able to thread Flask and use it along with Replit DB!
Profile icon
Profile icon