Danial Noori
Danial Noori

Reputation: 43

Deploying django app with gunicorn, Importerror in gunicorn log

I'm trying to deploy a django app using gunicorn and nginx based on this tutorial:

https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-14-04

But im having some trouble getting my gunicorn to work properly,

This is my /etc/init/gunicorn.conf:

description "Gunicorn application server handling myproject"

start on runlevel [2345]
stop on runlevel [!2345]

respawn
setuid me
setgid www-data


exec myprojectenv/bin/gunicorn --workers 3 --bind  unix:/myproject/myproject.sock myproject.wsgi:application

When in my virtualenv i run:

gunicorn --bind 0.0.0.0:8000 myproject.wsgi:application

everything is ok. But every time i start gunicorn i get this error in my gunicorn error log:

ImportError: No module named 'myproject'

I checked every possible option, but nothing changed. Is there anything im missing out? Thanks in advance.

EDIT:

I added a chdir line before exec:

chdir /myproject/myprojectenv

Im still getting

ImportError: No module named 'myproject'

Upvotes: 1

Views: 829

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 599946

When you run this manually, you are presumably already in the correct directory, so gunicorn can find the myproject.wsgi module. But when running under upstart, it won't be in that directory, so will have no idea where to find the file.

You can solve this by putting chdir /path/to/my/virtualenv before the exec line.

Upvotes: 1

Related Questions