5
votes

I'm trying to setup NGINX, uWSGI and Flask. I'm currently getting,


uWSGI Error

Python application not found


I get some strange errors in my uwsgi error file, which you can find at the bottom of my post.

I'll get straight to it, this is on a fresh VPS running Ubuntu 13.04 64bit, these are the commands I ran.

  • sudo apt-get update
  • sudo apt-get install build-essential
  • sudo apt-get install python-dev
  • sudo apt-get install python-pip
  • sudo apt-get install nginx
  • sudo apt-get install uwsgi
  • sudo apt-get install uwsgi-plugin-python
  • sudo pip install virtualenv

I then created a virtual environment, activated it and ran pip install flask I then made a folder called app and place a file called hello.py inside the same folder

/project
    /app
        -hello.py
    /bin
    /include
    /lib
    /local

This is my NGINX file (the nginx error file is empty)

server {
    listen 80;

    server_name project.domain.net;

    location / {
        try_files $uri @app;
    }

    location @app {
        include uwsgi_params;
        uwsgi_pass unix:/tmp/uwsgi.sock;
    }

    location ~ /\. {
        deny all;
    }
}

This is my uWSGI ini file

[uwsgi]
chdir = /home/user/projects/python/flask/project
uid = www-data
gid = www-data
chmod-socket = 666
plugin = python
socket = /tmp/uwsgi.sock
module = run
callable = app
virtualenv = /home/user/projects/python/flask/project

This is my hello.py file

from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello_word():
    return "Hello World!"

if __name__ == "__main__":
    app.run()

This is my uWSGI error file https://p.kk7.me/sepukinulu.applescript it's quite long so I figured I would paste it in a pastebin-style website. I can edit my post to include it here if this is not ok.

Any help would be greatly appreciated!

3

3 Answers

2
votes

You are requesting a 'run' module while your script is 'hello', infact:

ImportError: No module named run

2
votes

Fixed by adding PythonPath in my ini file, since I have my python files in an app subdirectory and by using the filename as the module.

pp=/home/user/projects/python/flask/project/app
module=filename
0
votes

For anyone who is facing the similar issue with Flask, Nginx & uWSGI set-up, you can follow / fork this repo: Python Flask with Nginx and uWSGI