Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No module named flask while running uWSGI

I have a very simple flask app (myflaskapp.py):

from flask import Flask

app = Flask(__name__)

@app.route('/')
def index():
    return "<span style='color:red'>I am app 1</span>"

If I run:

uwsgi --http-socket :3031 --plugin python --wsgi-file myflaskapp.py --callable app

I get the following output:

Traceback (most recent call last):
  File "myflaskapp.py", line 1, in <module>
    from flask import Flask
ImportError: No module named flask
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***

and I don't understand why. I have flask installed (pip install flask). If I run ipython and import flask it also works there. Any ideas? Thanks!

like image 280
agerrr Avatar asked Nov 24 '14 23:11

agerrr


2 Answers

In the end what worked for me was adding -H /path/to/virtualenv to the uWSGI command:

uwsgi --http-socket :3031 --plugin python --wsgi-file myflaskapp.py --callable app -H /path/to/virtualenv

I also had different Python versions in the virtualenv and for uWSGI. I'm still investigating if this could cause any problems.

like image 65
agerrr Avatar answered Oct 03 '22 01:10

agerrr


I ran into same problem once, as there was some version conflict

then instead of using pip to install uwsgi I did it by my package manager On ubuntu machine,

sudo apt-get install uwsgi

Also check and run myflaskapp.py without uwsgi that is by using app.run() in your code

*Note : That will be by werkzeug server.

like image 24
Harsh Daftary Avatar answered Oct 03 '22 01:10

Harsh Daftary