When starting uWSGI, the module is not called a flask

I have a very simple flash 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 am getting 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 a flask (sample cap) installed. If I run ipython and import the flask, it works there too. Any ideas? Thank!

+3


source to share


3 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 virtualenv and for uWSGI. I am still investigating if this might cause problems.

+11


source


I once faced one problem as there was a version conflict

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

sudo apt-get install uwsgi

      



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

* Note: This will be the werkzeug server.

+2


source


I ran into a similar issue and found the reason that if we have a module installed in a virtual environment (Flask in this case), we may need to add --virtualenv path in addition to the basic instructions needed to run a Flask application using uWSGI

Thus, the instruction according to the uWSGI document will look like this:

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

      

0


source







All Articles