Desiigner
Desiigner

Reputation: 2316

Gunicorn ModuleNotFoundError

I'm reading a book about TDD and Django and there's a deployment part. I have a problem trying to run gunicorn with the following command:

/root/sites/django_blog/virtualenv/bin/gunicorn --bind unix:/tmp/django_blog.socket django_blog.wsgi:application

It fails with the following error:

ModuleNotFoundError: No module named 'django_blog'

But when I activate my virtualenv and instead of writing the full pass to gunicorn I just go with:

gunicorn --bind unix:/tmp/django_blog.socket django_blog.wsgi:application

And everything works perfectly! The problem is I still need to run it the first way, because I wil use it in the nginx service file. I wrote about this error and tried a couple of solutions but they didn't work for me. I guess I have to do something with environment variables but I don't know what exactly.

Upvotes: 4

Views: 10363

Answers (1)

j-i-l
j-i-l

Reputation: 10957

You can specify a directory to gunicorn to switch to before the apps are loaded.

Simply add --chdir /path/to/directory to the launch.

In your case this might look as follows:

/root/sites/django_blog/virtualenv/bin/gunicorn --chdir /root/sites/django_blog/source --bind unix:/tmp/django_blog.socket django_blog.wsgi:application

Here is the link to the specific gunicorn settings documentation.

Hope that helps and happy coding!

Upvotes: 11

Related Questions