简体   繁体   中英

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.

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM