Unable to make gunicorn run on EC2 - django

I am following this tutorial to setup a Django-gunicorn-nginx server in AWS EC2. After installing all dependancies and making a change in wsgi.py as follows
import os, sys
# add the hellodjango project path into the sys.path
sys.path.append('/home/ubuntu/project/ToDo-application/')
# add the virtualenv site-packages path to the sys.path
sys.path.append('/home/ubuntu/.local/lib/python3.6/site-packages')
# poiting to the project settings
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "todo_app.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
I run gunicorn todo_app.wsgi and get the following error:
ubuntu#ip-172-31-61-163:~/project/ToDo-application$ gunicorn todo_app.wsgi
[2018-11-07 11:25:35 +0000] [8211] [INFO] Starting gunicorn 19.7.1
[2018-11-07 11:25:35 +0000] [8211] [INFO] Listening at: http://127.0.0.1:8000 (8211)
[2018-11-07 11:25:35 +0000] [8211] [INFO] Using worker: sync
[2018-11-07 11:25:35 +0000] [8215] [INFO] Booting worker with pid: 8215
[2018-11-07 11:25:35 +0000] [8215] [ERROR] Exception in worker process
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/gunicorn/arbiter.py", line 578, in spawn_worker
worker.init_process()
File "/usr/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 126, in init_process
self.load_wsgi()
File "/usr/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 135, in load_wsgi
self.wsgi = self.app.wsgi()
File "/usr/lib/python2.7/dist-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/usr/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 65, in load
return self.load_wsgiapp()
File "/usr/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
return util.import_app(self.app_uri)
File "/usr/lib/python2.7/dist-packages/gunicorn/util.py", line 377, in import_app
__import__(module)
File "/home/ubuntu/urbanpiper/ToDo-application/todo_app/wsgi.py", line 20, in <module>
from django.core.wsgi import get_wsgi_application
File "/home/ubuntu/.local/lib/python3.6/site-packages/django/__init__.py", line 1, in <module>
from django.utils.version import get_version
File "/home/ubuntu/.local/lib/python3.6/site-packages/django/utils/version.py", line 71, in <module>
#functools.lru_cache()
AttributeError: 'module' object has no attribute 'lru_cache'
Is this because of gunicorn having python2 dependancies and Django being on python3? I tried uninstalling gunicorn and trying it again but it did not work.

# WRONG:
# add the virtualenv site-packages path to the sys.path
sys.path.append('/home/ubuntu/.local/lib/python3.6/site-packages')
You ought to create a virutalenv for each uwsgi application you wish to host on the server, rather than setting the virtualenv to the path above. If you followed the linked tutorial word-by-word, then this is the part which needs more explaining:
Make a virtualenv and install your pip requirements
Essentially:
# install virtualenv3
sudo apt-get install virtualenv3
# create the virtual environment, specifically for the stated python version
virtualenv -p python3.6 TITLE_OF_VENV
# You now have a directory called TITLE_OF_VENV (You may wish to replace this
# with something more subtle).
# Activate the virtualenv for your current shell session
. TITLE_OF_VENV/bin/activate
# The dot above is intentional and is a quick way to write source, which
# imports the environment vars
Your shell prompt should now look like this: (TITLE_OF_VENV) ubuntu#ip-172-31-61-163:~/project/ToDo-application$ indicating that the venv is active. To switch out of the venv run the command deactivate.
Anything which you install with pip here will then live in the directory TITLE_OF_VENV/python3.6/site-packages (while this virutal environment is active). This has the advantage of keeping different project requirements separate.
Test the python version (with the venv still active):
(TITLE_OF_VENV)$ python --version
Python 3.6
Now install gunicorn into this virtual environment, along with any other project requirements:
(TITLE_OF_VENV)$ pip install gunicorn
(TITLE_OF_VENV)$ pip install -r requirements.txt
Update your uwsgi.py:
import os
# poiting to the project settings
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "todo_app.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
And then launch it from within the virtual environment:
(TITLE_OF_VENV)$ gunicorn todo_app.wsgi:application
You could add the -D flag to the gunicorn command also, which makes it run in the background. Also don't make this server publicly accessible. If it's a production box, you need to run it behind nginx!

Related

ImportError: No module named 'django_select2'

I am trying to deploy my django application on the pythonanywhere. I have install all the packages that requires for the application. I am also using django_select2 reusable app in my application.
Firstly, i activate virtual environment and install the django_select2 by this command :
$ pip install django_select2
When i execute below command
$ pip freeze
cryptography==2.2.2
Django==2.0.7
django-appconf==1.0.2
django-select2==6.1.0
Flask==1.0.2
Flask-JWT==0.3.2
Flask-SQLAlchemy==2.3.2
furl==1.2
idna==2.7
As you see django_select2 is also in the installed list. I also check site-packages inside my virual environment. There is also django_select2 folder.
However when i run my app it generates the ImportError: No module named 'django_select2' inside my error.log
Here is the part of my error.log
2018-07-14 14:18:53,934: Error running WSGI application
2018-07-14 14:18:53,934: ImportError: No module named 'django_select2'
2018-07-14 14:18:53,934: File "/var/www/harunergul_pythonanywhere_com_wsgi.py", line 22, in <module>
2018-07-14 14:18:53,935: application = get_wsgi_application()
2018-07-14 14:18:53,935:
2018-07-14 14:18:53,935: File "/usr/local/lib/python3.5/dist-packages/django/core/wsgi.py", line 13, in get_wsgi_application
2018-07-14 14:18:53,935: django.setup(set_prefix=False)
2018-07-14 14:18:53,935:
2018-07-14 14:18:53,935: File "/usr/local/lib/python3.5/dist-packages/django/__init__.py", line 27, in setup
2018-07-14 14:18:53,935: apps.populate(settings.INSTALLED_APPS)
2018-07-14 14:18:53,935:
2018-07-14 14:18:53,935: File "/usr/local/lib/python3.5/dist-packages/django/apps/registry.py", line 85, in populate
2018-07-14 14:18:53,936: app_config = AppConfig.create(entry)
2018-07-14 14:18:53,936:
2018-07-14 14:18:53,936: File "/usr/local/lib/python3.5/dist-packages/django/apps/config.py", line 90, in create
2018-07-14 14:18:53,936: module = import_module(entry)
Any suggestions? What i have missing?
The problem is application is not using virtual environment in this case. If we look at the below line we will see /usr/local/... . So the application is using pythonanywhere.com default environment.
File "/usr/local/lib/python3.5/dist-packages/django/core/wsgi.py", line 13,
which means whatever we install in our virtualenv has no effect on default server. In pythonanywhere.com there is virtualenv menu, be sure if you input correct path info in this menu.
The default pip on PythonAnywhere is for Python 2.7, so you've been installing your modules into the wrong version of Python (your web app is using 3.5). Use pip3.5 to install your modules.

Gunicorn Django [CRITICAL] WORKER TIMEOUT

Since I did a pip install google-api-python-client I have my Gunicorn workers stoping after timeout.
Django==1.5.3
Gunicorn==0.12.2
I'm not really sure if it comes from the pip but I did nothing particular except a database migration which migrated without error.
I use this command for Gunicorn:
gunicorn_django myapp.py --bind 127.0.0.1:8181 --timeout 120 --log-file /tmp/myapp.gunicorn.log --log-level info --workers 8 --pid /tmp/myapp.pid
I tryed the param --spew to have some trace but it doesn't help me:
[2016-06-13 21:09:52 +0000] [15602] [INFO] Worker exiting (pid: 15602)
[2016-06-13 21:09:52 +0000] [15601] [ERROR] Exception in worker process
Traceback (most recent call last):
File "/home/myapp/.local/share/virtualenvs/myapp/lib/python2.7/site-packages/gunicorn/arbiter.py", line 557, in spawn_worker
worker.init_process()
File "/home/myapp/.local/share/virtualenvs/myapp/lib/python2.7/site-packages/gunicorn/workers/base.py", line 126, in init_process
self.load_wsgi()
File "/home/myapp/.local/share/virtualenvs/myapp/lib/python2.7/site-packages/gunicorn/workers/base.py", line 136, in load_wsgi
self.wsgi = self.app.wsgi()
File "/home/myapp/.local/share/virtualenvs/myapp/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/home/myapp/.local/share/virtualenvs/myapp/lib/python2.7/site-packages/gunicorn/app/djangoapp.py", line 106, in load
return mod.make_wsgi_application()
File "/home/myapp/.local/share/virtualenvs/myapp/lib/python2.7/site-packages/gunicorn/app/django_wsgi.py", line 37, in make_wsgi_application
if get_validation_errors(s):
File "/home/myapp/.local/share/virtualenvs/myapp/lib/python2.7/site-packages/django/core/management/validation.py", line 35, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "/home/myapp/.local/share/virtualenvs/myapp/lib/python2.7/site-packages/django/db/models/loading.py", line 166, in get_app_errors
self._populate()
File "/home/myapp/.local/share/virtualenvs/myapp/lib/python2.7/site-packages/django/db/models/loading.py", line 72, in _populate
self.load_app(app_name, True)
File "/home/myapp/.local/share/virtualenvs/myapp/lib/python2.7/site-packages/django/db/models/loading.py", line 96, in load_app
models = import_module('.models', app_name)
File "/home/myapp/.local/share/virtualenvs/myapp/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/home/myapp/prod/apps/admin/models.py", line 5, in <module>
from django.contrib.auth.models import User
File "/home/myapp/.local/share/virtualenvs/myapp/lib/python2.7/site-packages/django/contrib/auth/models.py", line 18, in <module>
from django.contrib.auth.hashers import (
File "/home/myapp/.local/share/virtualenvs/myapp/lib/python2.7/site-packages/django/contrib/auth/hashers.py", line 8, in <module>
from django.test.signals import setting_changed
File "/home/myapp/.local/share/virtualenvs/myapp/lib/python2.7/site-packages/django/test/__init__.py", line 6, in <module>
from django.test.testcases import (TestCase, TransactionTestCase,
File "/home/myapp/.local/share/virtualenvs/myapp/lib/python2.7/site-packages/django/test/testcases.py", line 35, in <module>
from django.test import _doctest as doctest
File "/home/myapp/.local/share/virtualenvs/myapp/lib/python2.7/site-packages/django/test/_doctest.py", line 104, in <module>
import unittest, difflib, pdb, tempfile
File "/home/myapp/.local/share/virtualenvs/myapp/lib/python2.7/site-packages/pdbpp-0.7.2-py2.7.egg/pdb.py", line 38, in <module>
pdb = import_from_stdlib('pdb')
File "/home/myapp/.local/share/virtualenvs/myapp/lib/python2.7/site-packages/pdbpp-0.7.2-py2.7.egg/pdb.py", line 35, in import_from_stdlib
mydict = execfile(pyfile, result.__dict__)
File "/usr/local/lib/python2.7/pdb.py", line 3, in <module>
"""A Python debugger."""
File "/usr/local/lib/python2.7/pdb.py", line 3, in <module>
"""A Python debugger."""
File "/home/myapp/.local/share/virtualenvs/myapp/lib/python2.7/site-packages/gunicorn/debug.py", line 40, in __call__
line = src[lineno]
IndexError: tuple index out of range
[2016-06-13 21:09:52 +0000] [15601] [INFO] Worker exiting (pid: 15601)
As the problem came in the same time I installed google api client, I suspect pip to have upgraded some libs that are not compatible with my gunicorn or Django. I checked the pip log without success also.
If I run my Django app with runserver I can't see any bug, it seems very related to Gunicorn.
Is there a deeper way to debug Gunicorn ?
After struggling hours I finally found a clue in the pip log (HOME/.pip/pip.log) .
Installing google api client upgraded some of my previous libs like these:
Installing collected packages: pyopenssl, six, cryptography, idna, pyasn1, setuptools, enum34, ipaddress, cffi, pycparser
Found existing installation: pyOpenSSL 0.14
Uninstalling pyOpenSSL:
...
Found existing installation: six 1.9.0
Uninstalling six:
...
Found existing installation: cryptography 0.7.1
Uninstalling cryptography:
I noticed also some installing warning for cyptography. I decided to put back the old libs.
pyOpenSSL 0.14
six 1.9.0
cryptography 0.7.1
And it solved the problem. I don't know if it is pyopenssl or cryptography but it is getting really boring to have all these libs problems.
Hope this will help someone next time.

supervisor gunicorn process not started on instance restart

I am trying to configure gunicorn and supervisor for Django. I have configured gunicorn and i can run the django app using gunicorn manually. Now i have tried to configure the supervisor, the issue is that gunicorn process is not being started on instance restart. If i start the app from supervisorctl manually then app will start running.
When i see status in supervisorctl, it is FATAL and stderr says
Traceback (most recent call last):
File "/subscription/app/subscriptionapp/venvs/subscriptionapp/bin/gunicorn", line 11, in <module>
sys.exit(run())
File "/subscription/app/subscriptionapp/venvs/subscriptionapp/lib/python3.4/site-packages/gunicorn/app/wsgiapp.py", line 75, in run
WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
File "/subscription/app/subscriptionapp/venvs/subscriptionapp/lib/python3.4/site-packages/gunicorn/app/base.py", line 189, in run
super(Application, self).run()
File "/subscription/app/subscriptionapp/venvs/subscriptionapp/lib/python3.4/site-packages/gunicorn/app/base.py", line 72, in run
Arbiter(self).run()
File "/subscription/app/subscriptionapp/venvs/subscriptionapp/lib/python3.4/site-packages/gunicorn/arbiter.py", line 58, in __init__
self.setup(app)
File "/subscription/app/subscriptionapp/venvs/subscriptionapp/lib/python3.4/site-packages/gunicorn/arbiter.py", line 114, in setup
self.app.wsgi()
File "/subscription/app/subscriptionapp/venvs/subscriptionapp/lib/python3.4/site-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/subscription/app/subscriptionapp/venvs/subscriptionapp/lib/python3.4/site-packages/gunicorn/app/wsgiapp.py", line 66, in load
return self.load_wsgiapp()
File "/subscription/app/subscriptionapp/venvs/subscriptionapp/lib/python3.4/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
return util.import_app(self.app_uri)
File "/subscription/app/subscriptionapp/venvs/subscriptionapp/lib/python3.4/site-packages/gunicorn/util.py", line 355, in import_app
__import__(module)
ImportError: No module named 'config'
django app structure
subscription-project \
.codeintel
.ebextensions
.git
.gitignore
Makefile
Procfile
README.rst
common
config \
__init__.py
settings
urls.py
wsgi.py
djangoapps
locale
manage.py
requirements
runtime.txt
subscriptionapp_gunicorn.py
import multiprocessing
preload_app = True
timeout = 300
bind = "127.0.0.1:8000"
pythonpath = "/subscription/app/subscriptionapp/subscription-project"
workers = (multiprocessing.cpu_count()-1)
upstart supervisor config (/etc/init/supervisor.conf)
description "supervisord"
start on runlevel [2345]
stop on runlevel [!2345]
kill timeout 432000
setuid www-data
exec /subscription/app/supervisor/venvs/supervisor/bin/supervisord -n --configuration /subscription/app/supervisor/supervisord.conf
/subscription/app/supervisor/conf.d/subscriptionapp.conf
[program:subscriptionapp]
command=/subscription/app/subscriptionapp/venvs/subscriptionapp/bin/gunicorn -c /subscription/app/subscriptionapp/subscriptionapp_gunicorn.py config.wsgi
user=www-data
directory=/subscription/app/subscriptionapp/subscription-project
environment=PORT=8000,ADDRESS=127.0.0.1,LANG=en_US.UTF-8,DJANGO_SETTINGS_MODULE=config.settings.base,PATH="/subscription/app/subscriptionapp/venvs/subscriptionapp/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
stdout_logfile=/subscription/var/log/supervisor/subscriptionapp-stdout.log
stderr_logfile=/subscription/var/log/supervisor/subscriptionapp-stderr.log
killasgroup=true
stopasgroup=true
supervisord.conf
; supervisor config file
[unix_http_server]
file=/subscription/var/supervisor/supervisor.sock ; (the path to the socket file)
chmod=0700 ; sockef file mode (default 0700)
[supervisord]
logfile=/subscription/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)
pidfile=/subscription/var/supervisor/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
childlogdir=/subscription/var/log/supervisor ; ('AUTO' child log dir, default $TEMP)
; the below section must remain in the config file for RPC
; (supervisorctl/web interface) to work, additional interfaces may be
; added by defining them in separate rpcinterface: sections
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=unix:///subscription/var/supervisor/supervisor.sock ; use a unix:// URL for a unix socket
; The [include] section can just contain the "files" setting. This
; setting can list multiple files (separated by whitespace or
; newlines). It can also contain wildcards. The filenames are
; interpreted as relative to this file. Included files *cannot*
; include files themselves.
[inet_http_server]
port = 127.0.0.1:9001
[include]
files = /subscription/app/supervisor/conf.d/*.conf
Any help to resolve the issue will be highly appreciated.
It seems the config package is not available to gunicorn. Try explicitly adding the project directory to pythonpath like so:
/subscription/app/supervisor/conf.d/subscriptionapp.conf
[program:subscriptionapp]
command=/subscription/app/subscriptionapp/venvs/subscriptionapp/bin/gunicorn -c /subscription/app/subscriptionapp/subscriptionapp_gunicorn.py --pythonpath '/subscription/app/subscriptionapp/subscription-project,/subscription/app/subscriptionapp/venvs/subscriptionapp/lib/python3.4/site-packages/' config.wsgi
user=www-data
directory=/subscription/app/subscriptionapp/subscription-project
environment=PORT=8000,ADDRESS=127.0.0.1,LANG=en_US.UTF-8,DJANGO_SETTINGS_MODULE=config.settings.base,PATH="/subscription/app/subscriptionapp/venvs/subscriptionapp/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
stdout_logfile=/subscription/var/log/supervisor/subscriptionapp-stdout.log
stderr_logfile=/subscription/var/log/supervisor/subscriptionapp-stderr.log
killasgroup=true
stopasgroup=true
If this helps gunicorn to "find" config, if may be your gunicorn configuration file is not being loaded properly. Depending on your gunicorn version, loading settings from a python module may require a special form, as in docs:
Changed in version 19.4: Loading the config from a Python module requires the python: prefix.

Problems configuring deployment with Heroku/gunicorn/django

I'm trying to run my django application on heroku.
Folder structure:
app/
Procfile
docs/
...
project/
manage.py
wsgi.py
<django apps>
Procfile
web: gunicorn --pythonpath="$PWD/project" wsgi:application --log-file=-
Error I'm getting:
2015-02-16T16:05:00.646316+00:00 heroku[web.1]: Starting process with command `gunicorn --pythonpath="$PWD/project" wsgi:application --log-file=-`
2015-02-16T16:05:02.697633+00:00 app[web.1]: [2015-02-16 16:05:02 +0000] [3] [INFO] Listening at: http://0.0.0.0:44846 (3)
2015-02-16T16:05:02.709567+00:00 app[web.1]: [2015-02-16 16:05:02 +0000] [9] [INFO] Booting worker with pid: 9
2015-02-16T16:05:02.696968+00:00 app[web.1]: [2015-02-16 16:05:02 +0000] [3] [INFO] Starting gunicorn 19.1.1
2015-02-16T16:05:02.697790+00:00 app[web.1]: [2015-02-16 16:05:02 +0000] [3] [INFO] Using worker: sync
2015-02-16T16:05:02.793753+00:00 app[web.1]: [2015-02-16 16:05:02 +0000] [10] [INFO] Booting worker with pid: 10
2015-02-16T16:05:03.157305+00:00 app[web.1]: Traceback (most recent call last):
2015-02-16T16:05:03.157311+00:00 app[web.1]: File "/app/.heroku/python/bin/gunicorn", line 11, in <module>
2015-02-16T16:05:03.157351+00:00 app[web.1]: sys.exit(run())
2015-02-16T16:05:03.157383+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 74, in run
2015-02-16T16:05:03.157461+00:00 app[web.1]: WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
2015-02-16T16:05:03.157463+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 185, in run
2015-02-16T16:05:03.157506+00:00 app[web.1]: super(Application, self).run()
2015-02-16T16:05:03.157527+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 71, in run
2015-02-16T16:05:03.157604+00:00 app[web.1]: Arbiter(self).run()
2015-02-16T16:05:03.157607+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 196, in run
2015-02-16T16:05:03.157635+00:00 app[web.1]: self.halt(reason=inst.reason, exit_status=inst.exit_status)
2015-02-16T16:05:03.157656+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 292, in halt
2015-02-16T16:05:03.157730+00:00 app[web.1]: self.stop()
2015-02-16T16:05:03.157744+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 343, in stop
2015-02-16T16:05:03.157814+00:00 app[web.1]: time.sleep(0.1)
2015-02-16T16:05:03.157836+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 209, in handle_chld
2015-02-16T16:05:03.157887+00:00 app[web.1]: self.reap_workers()
2015-02-16T16:05:03.157908+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 459, in reap_workers
2015-02-16T16:05:03.158009+00:00 app[web.1]: raise HaltServer(reason, self.WORKER_BOOT_ERROR)
2015-02-16T16:05:03.158075+00:00 app[web.1]: gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
2015-02-16T16:05:03.904714+00:00 heroku[web.1]: Process exited with status 1
2015-02-16T16:05:03.914410+00:00 heroku[web.1]: State changed from starting to crashed
Update 1
My wsgi.py file
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config")
os.environ.setdefault("DJANGO_CONFIGURATION", "Production")
from configurations.wsgi import get_wsgi_application
application = get_wsgi_application()
Here I am just adding some text because SO has this silly minimum amount of text that must be written in a question. I mean, I do get it that quality needs to be kept, but if the problem is self explanatory why force people to write unneeded text? Thanks and have a great day!
Adding --preload to the gunicorn command in the Procfile will make your Traceback a lot more readable and show you the actual errors.
Exmaple:
gunicorn project.wsgi:application --preload --workers 1
I had a similar problem, after reading he docs for gunicorn, I was able to add
--log-level debug
to the
web: gunicorn project.wsgi:application --log-file -
such that its
web: gunicorn project.wsgi:application --log-file - --log-level debug
In my case the path was also an issue.
Finally found the solution, it was a missing dependency of django-organizations. I find it crazy that there is no way (at least not that I could find) to see any useful error output from heroku. I finally did
heroku run bash --app <app_name>
and then ran the wsgi.py file line by line, finally getting some meaningful error on
from configurations.wsgi import get_wsgi_application # noqa
It was then clear that it's a missing module error, installed it and everything runs perfectly fine.
Change your Procfile to:
web: gunicorn project.wsgi:application --log-file=-
You're missing the project module in the python path to the wsgi.py file.
I solved it. I followed these steps:
Remove all the unused libraries.
Delete requirements.txt file.
Create a new requirements.txt file.
Commit to Git and then deploy on Heroku.

Django Gunicorn ImportError: No module named django.core.wsgi

I have created a Django application but now have plans to use some asynchronous (real-time) functionality in some areas of the site. After doing some research I think I should use gevent-socketio and therefore it is required I switch the application server to Gunicorn.
I have fallen at the first hurdle of deploying Gunicorn, I have installed with the command sudo apt-get install gunicorn and try to run my application with gunicorn project.wsgi:application but it fails and produces the following error:
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/gunicorn/arbiter.py", line 473, in spawn_worker
worker.init_process()
File "/usr/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 100, in init_process
self.wsgi = self.app.wsgi()
File "/usr/lib/python2.7/dist-packages/gunicorn/app/base.py", line 115, in wsgi
self.callable = self.load()
File "/usr/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 33, in load
return util.import_app(self.app_uri)
File "/usr/lib/python2.7/dist-packages/gunicorn/util.py", line 362, in import_app
__import__(module)
File "/home/alex/django_projects/fantasymatchday_1/fantasymatchday_1/wsgi.py", line 13, in <module>
from django.core.wsgi import get_wsgi_application
ImportError: No module named django.core.wsgi
2014-11-20 17:31:45 [6605] [INFO] Worker exiting (pid: 6605)
2014-11-20 17:31:45 [6600] [INFO] Shutting down: Master
2014-11-20 17:31:45 [6600] [INFO] Reason: Worker failed to boot.
Can anybody give me a clue to what I need to do from here?
I am using python 3.4.0 and Django 1.6
You have to install django and gunicorn in the same environment.
If you use virtualenv make sure you have both in the same virtual environment.