ModuleNotFoundError: No module named 'flask' (unsolved)

Question:
I have a flask application that was working fine. now, when i try to run it i get an error that flask isn’t found. i have tried uninstalling and reinstalling poetry, manually installing flask (via pip and poetry), forking the repl, and starting fresh with a new repl and download my code from github. when i look at the pyproject.toml file, i see flask listed. when run “poetry show” i see flask listed. but then when i run the app, i get… ModuleNotFoundError: No module named ‘flask’

nothing seems to work.

any ideas?

(ps it’s a private repl so i can’t link to it, unfortunately)

Repl link/Link to where the bug appears:

Screenshots, links, or other helpful context:

[tool.poetry]
name = "python-template"
version = "0.1.0"
description = ""
authors = ["Your Name <you@example.com>"]

[tool.poetry.dependencies]
python = ">=3.10.0,<3.11"
numpy = "^1.22.2"
replit = "^3.2.4"
urllib3 = "^1.26.12"
Flask-WTF = "^1.1.1"
openai = "^0.27.8"
WTForms = "^3.0.1"
Flask-SQLAlchemy = "^3.0.5"
Flask-Bcrypt = "^1.0.1"
inflect = "^7.0.0"
Flask-Session = "^0.5.0"
tiktoken = "^0.5.1"
scripts = "^2.0"
SQLAlchemy = "^2.0.23"
django-lookup-tables = "^0.15.3"
django-shop = "^1.2.4"
auth = "^0.5.3"
config = "^0.5.1"
django-follow = "^0.6.1"
plan = "^0.5"
psycopg2 = "^2.9.9"
requests = "^2.31.0"
six = "^1.16.0"
authlib = "^1.2.1"
flask = "2.2.5"

[tool.poetry.dev-dependencies]
debugpy = "^1.6.2"
replit-python-lsp-server = {extras = ["yapf", "rope", "pyflakes"], version = "^1.5.9"}

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

Have you tried running poetry add flask in Shell?

yes. i get a message that “the following packages are already present…” and then lists flask.

Try uninstalling flask and reinstalling it through the shell

tried. i get this error below. so then i force install version 2.2.5, but that doesn’t work either. still get message that flask module not found, even though i see it in pyproect.toml and when i run poetry show

→ poetry add flask
Using version ^3.0.0 for flask

Updating dependencies
Resolving dependencies…

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

my best guess is that i have some sort of conflict in the vm, where replit is pointing to different versions or paths? how else could i see flask in poetry show and in pyproject.toml, but then the application doesn’t find it.

3 Likes

so odd. the same code used to work. poetry lists flask, pyproject.toml lists flask… but then modulefounderror. seems like it has to be something about versions or file paths. i wonder about trying another ide, as an experiment.

1 Like

For a brute force debugging:
Check the hidden folder (show hidden files first), .pythonlibs/lib/python3.10/site-packages and make sure that flask is present.
If it is not, then the problem is that it did not actually install.
If it is present, then check the python path (defines where to look for packages), two ways to do this:

import sys
print(sys.path)

or in shell:

echo $PYTHONPATH

Check that the path I said above is in python path.

they are the same. well, i just created a new repl and copied over each file. everything runs fine (again). bummer of a solution though, bc it might happen again.

What I do is do poetry remove flask and then in my code, leave Flask. Since the Replit package installs Flask, it may give you an error upon every time you start your code, but it will ignore it and wstill run the code. Alas, very annoying :frowning:

okay, thanks for reading and providing the tip. will give a try if i end up back in the same spot.

1 Like

did you try the solutions in this topic

1 Like

Yes I tried that. Didn’t work.

The problem was that flask was installed, listed in poetry and pyproject.toml… but then my application couldn’t find it. My best guess (and I’m a newer engineer mind you) is that there is a conflict with python name or file path. So I had two version running, getting confused. Or something like that.

To solve the problem, I ended up just creating an entirely new repl, then instead of pulling my latest git file (which didn’t work when I tried it)…. I manually copied over the files to the new repl. This worked. And side note, it seems to have updated several packages along the way (e.g. I had to manually update openai api before… now I get it for “free” with the package manager).