django + virtualenv + gunicorn - No module named django.core.wsgi?

It might not be the case for this particular question However I encountered a similar issue and was led here by google. So I place this answer here in the hope to be useful for others.

The problem for me was that gunicorn was being ran by a globally installed package not the one that was installed in the virtual environment. To make sure that whether this is the case for you or not, just simply run the which gunicorn and check it is coming from your virtualenv bin directory. If it is not coming from your virtual env bin directory follow these steps:

  1. Deactivated the env.
    • deactivate env
  2. Uninstalled the globally installed gunicron
    • pip uninstall gunicorn
  3. Activate the env. [ I use virtualenvwrapper for virtualenv management and I recommend you to do so. ]
    • workon env

Now gunicorn should work as expected.


I have same issue and I solved it by removing gunicorn which installed with system package manager(apt-get etc).

apt-get installing gunicorn to site-packages of python2 and pip installing Django to site-packages of python3. So Gunicorn and Django not in same site-packages directory. So gunicorn cannot find django. Insalling Gunicorn and Django in same package dir should solve the problem.


In /etc/systemd/system/gunicorn.service, make sure your Working Directory is pointing to your app directory.

[Unit]
Description=gunicorn daemon
After=network.target

[Service]
User=sammy
Group=www-data
WorkingDirectory=/home/sammy/myproject
ExecStart=/home/sammy/myproject/myprojectenv/bin/gunicorn --access-logfile - --workers 3 --bind unix:/home/sammy/myproject/myproject.sock myproject.wsgi:application