Score:1

Unable to deploy simple flask app on ubuntu vps

cn flag

I am trying to deploy a simple flask app on an VPS running Ubuntu 20 and LAMP

The app runs fine when I execute it with flask run from inside the app folder

However the server log has errors:

[Sun Oct 24 14:55:03.464311 2021] [wsgi:error] [pid 5655] [client 90.198.214.109:59097]     from FlaskApp import app as application
[Sun Oct 24 14:55:03.464323 2021] [wsgi:error] [pid 5655] [client 90.198.214.109:59097]   File "/var/www/FlaskApp/FlaskApp/__init__.py", line 1, in <module>
[Sun Oct 24 14:55:03.464363 2021] [wsgi:error] [pid 5655] [client 90.198.214.109:59097]     from flask import Flask
[Sun Oct 24 14:55:03.464386 2021] [wsgi:error] [pid 5655] [client 90.198.214.109:59097] ImportError: No module named flask

The code and instructions are taken from here: https://www.digitalocean.com/community/tutorials/how-to-deploy-a-flask-application-on-an-ubuntu-vps

When going to the server's IP, an error message shows up:

Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request.

EDIT:

When I run the code using command sudo python __init__.py it gives the error that cannot import flask from Flask while using the command sudo python3 __init__.py works just fine. It seems like the whichever script invokes the wsgi file is calling using the python style of calling which triggers the error of being unable to start the script

djdomi avatar
za flag
please add your answer as an answer and mark this as accepted! Else we will find this question within until serverfault.com gets out of business ;) thanks
Score:0
cn flag

ANSWER:

Turns out the issue was in wsgi.py and which python directory it invokes (has to specifically be /python3, not /python)

Fixed by changing top line in wsgi file to this

#!/usr/bin/python3.8 from tutorial #!/usr/bin/python

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.