N
N
Nikolay Baranenko2020-08-26 15:26:23
Python
Nikolay Baranenko, 2020-08-26 15:26:23

Why is the object not being imported from module ModuleNotFoundError: No module named 'app'?

Hello.

I have such a project folder structure

5f4653ce6e4ba689665495.png

in wcgi.py, I register the connection of the server1 object from app.main

from app.main1 import server1

if __name__ == "__main__":
    server1.run(host='0.0.0.0', port=8118)


in main1/app.py

from flask import Flask
from flask import request, jsonify
from random import sample

server1 = Flask(__name__)


def run_request():
    index = int(request.json['index'])
    list = ['red', 'green', 'blue', 'yellow', 'black']
    return list[index]


@server1.route('/', methods=['GET', 'POST'])
def hello_world():
    if request.method == 'GET':
        return 'The model is up and running. Send a POST request'
    else:
        return run_request()


I run it

app$ gunicorn -w 1 -b 0.0.0.0:8118 wsgi:server

returns an error

File "/home/drno/IdeaProjects/inclouds/backend/app/wsgi.py", line 1, in <module>
    from app.main1 import server1
ModuleNotFoundError: No module named 'app'


What did I do wrong and how to fix it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2020-08-26
@drno-reg

The idea is so
from main1.app import server1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question