'Encountered few errors after starting project with flask run such as ModuleNotFoundError: No module named api
I have flask based python project that I run with flask run. Full picture of errors:
File "D:\ias\project_name\wsgi.py", line 4, in <module>
from app import app as application
File "D:\ias\project_name\entity\__init__.py", line 4, in <module>
from api import *
ModuleNotFoundError: No module named 'api'
Below is my project's files structure and content of troubled files:
project_folder/
entity/
__init__.py
api.py
wsgi.py
app.py
__init__.py contains this piece of code:
from api import *
wsgi.py contains:
from app import app as application
if __name__ == '__main__':
application.run()
app.py contains:
app = Flask(__name__)
app.config.from_object(__name__)
Solution 1:[1]
You can do some of the modifications to make it work better I suppose.
From:
project_folder/
entity/
__init__.py
api.py
wsgi.py
app.py
To:
project_folder/
entity/
app/
__init__.py # Import from app.api the blueprint, initialize the create_app() from here.
api/
__init__.py
api.py
wsgi.py
app.py # Call the create_app() from app to initialize and then do app.run().
Solution 2:[2]
You don't have required permissions in the given directory.
You can run
sudo npm start
or update permissions for the directory
sudo chmod 777 -R Your_Dir/
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Karan Kaushik |
