1

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

Gerald Schneider
  • 23,274
  • 8
  • 57
  • 89
  • 1
    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 – djdomi Oct 24 '21 at 20:20

1 Answers1

0

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