Bhojendra Rauniyar
Bhojendra Rauniyar

Reputation: 85545

ModuleNotFoundError: No module named 'hello'

I did something really bad. I don't know what I did. I created a test project with hello.py where I did some mistake when running with some command. Now, I have deleted that and back to the real project, and I got the following error:

File "/home/bhojendra/anaconda3/envs/myenv/lib/python3.9/site-packages/flask/cli.py", line 240, in locate_app import(module_name) ModuleNotFoundError: No module named 'hello'

I don't have even the word hello anywhere in the project.

I have removed all pycaches from the project, cleaned the conda conda clean -a, removed myenv environment and removed pip cache directory. Then, I re-created the environment and and re-installed the requirements and when launching the project with flask run, it throws that error again. Not sure what's happening.

It might be the issue with flask cache, I don't know how to overcome this issue.

Upvotes: 0

Views: 1791

Answers (1)

AS11
AS11

Reputation: 1461

In your environment, you likely left your FLASK_APP set to the file hello, so it was trying to run that, although it doesn't exist. You just have to export or set your flask app based on what machine you are using.

Unix Bash (Linux, Mac, etc.):

$ export FLASK_APP=hello
$ flask run

Windows CMD:

> set FLASK_APP=hello
> flask run

Windows PowerShell:

> $env:FLASK_APP = "hello"
> flask run

You could also unset the export:

unset FLASK_APP

And then set the flask app

Upvotes: 1

Related Questions