3π
you should actually run it as follow:
gunicorn helloapp.wsgi:application
- Basic usage of gunicorn:
gunicorn [OPTIONS] APP_MODULE
Where APP_MODULE
is of the pattern $(MODULE_NAME):$(VARIABLE_NAME)
11π
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:
- Deactivated the env.
deactivate env
- Uninstalled the globally installed gunicron
pip uninstall gunicorn
- Activate the env. [ I use virtualenvwrapper for virtualenv management and I recommend you to do so. ]
workon env
Now gunicorn should work as expected.
- Django admin.TabularInline auto insert three blank row
- Django: Distinct foreign keys
- Use a django built in filter in code (outside of a template)
- Send email to bcc and cc in django
- Could not import 'oauth2_provider.ext.rest_framework.OAuth2Authentication' for API setting 'DEFAULT_AUTHENTICATION_CLASSES'
9π
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.
- Django reverse error: NoReverseMatch
- Django, Security and Settings
- Difference between self.request and request in Django class-based view
- Use of unicode in Django
5π
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
1π
As pointed out here and elsewhere, the root of the problem as indidcated by the error message is that gunicorn
cannot find the django modules. The question then becomes why that is the case and there can be many different reasons. In my case on a Ubuntu bionic host without virtualenv it was due to the fact that I had installed python3-django and gunicorn (the latter being a python2 package).
The solution was to install python3-gunicorn, remove gunicorn and run gunicorn as gunicorn3
.
0π
Wrong directory:
check your current directory then
cd
to the right directory before
calling.
Example:
Incorrect:
~/project_name/main$ gunicorn3 --bind 0.0.0.0:8000 main.wsgi:application
Correct:
~/project_name/main$ cd ..
~/project_name$ gunicorn3 --bind 0.0.0.0:8000 main.wsgi:application
- How can I test if my redis cache is working?
- Celery workers unable to connect to redis on docker instances
- Django Testing β Hard code URLs or Not
- How to test a Django on_commit hook without clearing the database?
0π
I am using poetry and pyenv. In my case it turns out the gunicorn instance that I was running was referencing a system level installation, as opposed to the one installed in the virtual environment. I figured this out by running which gunicorn
and comparing it to the output of pyenv which gunicorn
.
What solved it for me was doing
$(pyenv which gunicorn) <app_name>.wsgi:application --bind 0.0.0.0
- Best way to reference the User model in Django >= 1.5
- Coverage in parallel for django tests
- TimeField format in Django template
0π
I used a combination of the answers above and another solution. I deactivated virtual env and Installed Django, then I activated it and ran the command like this: gunicorn --bind 0.0.0.0:8000 myproject.wsgi:application
- Can you declare multiple with variables in a django template?
- Does changing a django models related_name attribute require a south migration?
- How to display "This many months ago" in Django using Humanize?
- Django Forms: Hidden model field?