1

I am trying to get uwsgi working in combination with nginx for a flask application. This is UWSGI ini file:

[uwsgi]
socket = 127.0.0.1:8001
processes = 4
module = run:manager
virtualenv = /var/www/test/venv
chdir = /var/www/test
logto = uwsgi.log

In the directory /var/www/test I have this file run.py

from flask.ext.migrate import Migrate, MigrateCommand
from flask.ext.script import Manager
from app import app, db

if __name__ == "__main__":
    migrate = Migrate(app, db)
    manager = Manager(app)
    manager.add_command('db', MigrateCommand)
    manager.run()

When I run it I get this error:

Set PythonHome to /var/www/test/                                                                         
ImportError: No module named site

Can anyone tell me where I am going wrong please?

1

In my case, being new to uwsgi, I didn't understand where virtualenvs end up by default (under ~/.virtualkenvs directory). For my moztrap app, the appropriate configuration turned out to be:

[uwsgi]
vhost = true
plugins = python
socket = /tmp/testa.sock
master = true
enable-threads = true
module = wsgi:application
processes = 2
wsgi-file = /home/ianh/moztrap/moztrap/deploy/wsgi.py
virtualenv = /home/ianh/.virtualenvs/moztrap
chdir = /home/ianh/moztrap
touch-reload = /home/ianh/moztrap/reload

I messed around with module and virtualenv, and this is the combination that worked for me. Note, the wsgi.py file contains the following.

"""WSGI entry-point for MozTrap."""

import os
import sys

base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, base_dir)

# Set default settings and instantiate application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "moztrap.settings.default")

from django.core.handlers.wsgi import WSGIHandler
application = WSGIHandler()

I also tried loading uwsgi using apt-get then pip, but didn't in the end need to do a symlink - so I preume its using the one apt-get installed.

Thanks mainly to the following (and a few others that lack of rep points wont let me thank):

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.