Uwsgi-nginx-flask: Unable To Load App 0 (mountpoint='') (callable Not Found Or Import Error)
Solution 1:
With
[uwsgi]module = main
callable = app
uwsgi will import main
, extract app
from within it, expecting app
to be an instance of a WSGI application. An instance of Flask is a WSGI application. A standard way of doing this within the structure you're using is
from app importcreate_appapp= create_app()
The code you posted isn't calling create_app()
when using uwsgi, because main.py
is being imported. And when you are actually calling create_app()
, you'll need to remove the unused arg1
and arg
arguments from the definition.
Doing
from app import create_app as application
confuses things, especially if at one point you'd tried callable = application
.
Solution 2:
can you try changing uwsgi.ini
to
[uwsgi]module = main
callable = app.app
Solution 3:
For people that are running uwsgi + Docker and have run into the unable to load app 0 callable not found error, try changing the "app" folder name to "application" if it's not absolutely critical to have the folder name as "app"
I've just spent 2 days trying to reorganise our code repo structure and our internal Docker structure. This was the last issue I had to tackle and it was pretty frustrating one to resolve.
uWSGI is looking for a folder called "application" by default, as per documentation here:
I messed around with uwsgi.ini settings (callable, chdir), but none worked for me. I've also tried some of the suggestions above but it didn't work for me either.
In case changing the name to application doesn't work, try setting the PYTHONPATH environment variable as well. Depending on your directory structure of your project, you may need to give Python's Loading mechnaism some help in determining where to look for files. This was the other major issue that I had to resolve earlier in the process.
I had mine set in docker-compose.yml. I couldn't get it to work in dockerfile. I believe you can set in uwsgi.ini but I never tried it myself.
I've listed my configurations. Hopefully there's enough in here to steer people in the right direction.
Example Configuration:
OurDirectory structure (Docker):
application/
{Component}/
Common/
uwsgi.ini:
[uwsgi]
module = main
callable = application/{Component}
docker-compose.yml:
{Component}:
environment:
PYTHONPATH: /application/{Component}:/application/Common:/application
main.py:
if __name__ == '__main__':
app.run(<YourAppRunArguments>)
else:
application = app
Post a Comment for "Uwsgi-nginx-flask: Unable To Load App 0 (mountpoint='') (callable Not Found Or Import Error)"