Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gunicorn ImportError: No module named flask

I have an anaconda virtual environment and I have already install flask in the virtual environment using pip when I run my app using

$ python app.py 

then it's working correctly, But when I run it with gunicorn I't showing that no module flask
app.py

from flask import Flask

app = Flask(__name__)

@app.route('/')
def index():
    return "Hello World"

if __name__ == '__main__':
    app.run(debug=True)

wsgi.py

from app import app
if __name__ == "__main__":
    app.run()
 $ gunicorn --bind 0.0.0.0:8000 wsgi
[2019-07-23 12:39:24 +0000] [25612] [INFO] Starting gunicorn 19.9.0
[2019-07-23 12:39:24 +0000] [25612] [INFO] Listening at: http://0.0.0.0:8000 (25612)
[2019-07-23 12:39:24 +0000] [25612] [INFO] Using worker: sync
[2019-07-23 12:39:24 +0000] [25616] [INFO] Booting worker with pid: 25616
[2019-07-23 12:39:24 +0000] [25616] [ERROR] Exception in worker process
Traceback (most recent call last):
  File "/home/rahul/.local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
    worker.init_process()
  File "/home/rahul/.local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 129, in init_process
    self.load_wsgi()
  File "/home/rahul/.local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/home/rahul/.local/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/home/rahul/.local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load
    return self.load_wsgiapp()
  File "/home/rahul/.local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/home/rahul/.local/lib/python2.7/site-packages/gunicorn/util.py", line 350, in import_app
    __import__(module)
  File "/home/rahul/test_folder/wsgi.py", line 1, in <module>
    from app import app
  File "/home/rahul/test_folder/app.py", line 1, in <module>
    from flask import Flask
ImportError: No module named flask
[2019-07-23 12:39:24 +0000] [25616] [INFO] Worker exiting (pid: 25616)
[2019-07-23 12:39:24 +0000] [25612] [INFO] Shutting down: Master
[2019-07-23 12:39:24 +0000] [25612] [INFO] Reason: Worker failed to boot.
like image 504
Rahul Verma Avatar asked Nov 07 '22 15:11

Rahul Verma


1 Answers

i think you forget to add app when run gunicorn

gunicorn --bind 0.0.0.0:8000 wsgi:app

it will run like this

→ gunicorn --bind 0.0.0.0:8000 wsgi:app
[2021-06-06 12:39:44 +0700] [54561] [INFO] Starting gunicorn 20.1.0
[2021-06-06 12:39:44 +0700] [54561] [INFO] Listening at: http://0.0.0.0:8000 (54561)
[2021-06-06 12:39:44 +0700] [54561] [INFO] Using worker: sync
[2021-06-06 12:39:44 +0700] [54563] [INFO] Booting worker with pid: 54563

and tested like this

→ curl http://localhost:8000
Hello World% 
like image 105
ferdina kusumah Avatar answered Nov 14 '22 22:11

ferdina kusumah