Cannot install gunicorn on Ubuntu - django

I'm trying to install gunicorn in my virtual env, but get the following:
$ pip install gunicorn
Downloading/unpacking gunicorn
Downloading gunicorn-0.14.2.tar.gz (203Kb): 203Kb downloaded
Running setup.py egg_info for package gunicorn
warning: no files found matching '*' under directory 'debian'
Installing collected packages: gunicorn Found existing installation: gunicorn 0.14.2
Uninstalling gunicorn:
Successfully uninstalled gunicorn
Running setup.py install for gunicorn
warning: no files found matching '*' under directory 'debian'
Installing gunicorn_paster script to /home/aemdy/Documents/projects/reborn/env/bin
Installing gunicorn script to /home/aemdy/Documents/projects/reborn/env/bin
Installing gunicorn_django script to /home/aemdy/Documents/projects/reborn/env/bin
Successfully installed gunicorn
Cleaning up...
And when I use python manage.py run_gunicorn for django it says that this is unknown command. I have added gunicorn to INSTALLED_APPS.

Warnings like that appear sometimes when installing apps. I believe it's related to cleanup pip tries to do, but it doesn't matter regardless. As the console output says "Successfully installed gunicorn". So no problems there.
With gunicorn installed, the only other requirement is adding gunicorn to INSTALLED_APPS. If you've done that as well, you're done. run_gunicorn will be available.
So, if it's not working, one of the following is in play:
Gunicorn isn't actually installed. However, you should get an error trying to reference in in INSTALLED_APPS in that scenario. Check your virtualenv's site-packages directory to ensure there's gunicorn folder there.
You installed Gunicorn in a different virtualenv. Again, you should be getting an error just as in #1. And, just as in #1, check to make sure it's actually in the proper virtualenv's site-packages directory
You don't have the virtualenv activated. However, same error as in #1 and #2 applies here.
You really don't have gunicorn in INSTALLED_APPS or a compiled version of settings.py is being used that doesn't have it in INSTALLED_APPS. Delete settings.pyc if it exists.

I just ran into this issue. What I did was try to run the app using runserver which led to me seeing the hostname on the server was not set(and thus can't get an IP address). Once we fixed that issue the command worked again.
It is a little misleading to see:
Unknown command: 'run_gunicorn'
Type 'manage.py help' for usage.
when the hostname is not set...confusing I know but I hope this helps someone in the future.

Did you remember to add gunicorn to your INSTALLED_APPS?

Related

What is the propper way to debug gunicorn?

I am trying to deploy my very first Django applicatin on heroku. Gunicorn gives me this error: gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
In this answer https://stackoverflow.com/a/55623889 command gunicorn app:application --preload -b 0.0.0.0:5000 is said to give detailed error message, but as its comments state it is not clear what words to replace with what. For instance somewhere I saw something similar called with <name of my app>.wsgi. To make matter worse name of my Django app in local is different from the one on Heroku.
Also it is not clear to me should this be called strait from terminal (within virtual env) or should I be using some sort of gunicorn CLI.
So what is the actual propper way to figure out what is failing gunicorn?
I've faced similar issues in the past. I hope this might help:
Make sure gunicorn is installed in your activated virtual environment project by running pip freeze in the terminal to verify it's installation. If it is not listed, in the activated virtual environment, run pip install gunicorn or else if you are using pipenv, run pipenv install gunicorn. Don't forget to update the requirements.txt file by running pip freeze > requirements.txt
In the Procfile which is within the project_directory type the syntax:
web: gunicorn your_django_project_name.wsgi --log-file -
N.B: There should be a space between;
The --log-file and the - next to it.
web: and the gunicorn part of the code.
Finally add, commit and push the changes to the heroku server.

django ModuleNotFoundError: No module named 'debug-toolbar'

I just tried to install the django-debug-toolbar. I believe I followed all the steps as indicated in the docs. I am using docker, so I included the following in my settings:
if os.environ.get('DEBUG'):
import socket
hostname, _, ips = socket.gethostbyname_ex(socket.gethostname())
INTERNAL_IPS = [ip[: ip.rfind(".")] + ".1" for ip in ips] + ["127.0.0.1", "10.0.2.2"]
After installing, I ran docker-compose build then docker-compose up -d. docker-compose logs and docker-compose exec web python manage.py collectstatic show the error
ModuleNotFoundError: No module named 'debug-toolbar'
The only thing I think I did differently from the docs is that I use pipenv. I exited docker-compose and then installed via pipenv install django-debug-toolbar. Debug toolbar is in my pipfile.
I'm never sure if I'm supposed to exit docker-compose before install a module via pipenv (or if it matters). I also tried installed via docker-compose exec web pipenv install django-debug-toolbar, shut down the container, then docker-compose up -d --build but the module not found error is still there.
Typo error on my part. In settings.py under installed apps I had debug-toolbar instead of debug_toolbar.

how can I fix the application an error in the Heroku cloud?

I uploaded my website project on Heroku cloud a while ago and I needed to edit some stuff with the project and when I reupload the website again in the same app directory I get the message from Heroku that says Application error then I tried to create a new app directory in Heroku by command: create heroku appname
and when I upload my project doesn't work again with the different directory on Heroku so what is the step I missed here?
I followed up this lesson https://www.youtube.com/watch?v=MoX36izzEWY&t=1707s step by step and I don't know what the step I missed or what is may the new in Heroku didn't exist in this tutorial?
- I did create a virtual environment
- I did create all files that Heroku needs like:
ProcFile
pipfile
requirements.txt
and I installed everything as the tutorial said exactly: (gunicorn, django-heroku, whitenoise and so else)
last note:
I'm on Linux Ubuntu
I found the answer:
I had to install gunicorn into PipFile file side by side requirements.txt file
so, for the future coders, this is my mistake you have to install gunicorn into two files and they are: requirements.txt and PipFile
for Pipfile file you have to run the following command:
- $ pip3 install pipenv
- $ pipenv install gunicorn
Note that:
These commands run on the Linux system.

Gunicorn not working on Amazon ec2 server

I am trying to deploy a django website on an aws ec2 instance (ubuntu 18.04) following this tutorial that is consistent with other online resources. Everything is working fine but there is some issue with gunicorn. The worker doesn't seem to boot.
I figured there was something wrong with my installation and I tried uninstalling and installing with different commands-
inisde my virtualenv with
pip install gunicorn
and
sudo -H pip install gunicorn
I even physically deleted all gunicorn files and reinstalled gunicorn but its always the same. Where have I gone wrong?
p.s: I had initially done sudo apt-get
From the screenshot you attached, it seems that gunicorn is installed correctly, but perhaps you have not passed a configuration file. The command to run gunicorn with a configuration is
gunicorn -c /path/to/gunicorn.conf.py myapp.wsgi:application

gunicorn not found on heroku

I want to deploy a very basic Django app on Heroku. I followed the instructions, but the browser shows me the Heroku error page and the heroku logs say
bash: gunicorn: command not found
I have gunicorn in my requirements.txt and configured the wsgi.py and Procfile as instructed by the documentation. What else can I try?
Edit: I also tried to install gunicorn manually on Heroku (heroku run pip install gunicorn), which worked fine, so I am pretty sure that gunicorn is installed. Why doesn't Heroku find it?
Edit 2: It seems that I can install gunicorn manually (heroku run bash and then pip install gunicorn:
~ $ gunicorn
usage: gunicorn [OPTIONS] [APP_MODULE]
gunicorn: error: No application module specified.
but when i log out and log in to the bash again, i get:
~ $ gunicorn
bash: gunicorn: command not found
Heroku seems to install but then discard gunicorn. How can that be?
Hi got the same problem but this might help:
Go to this:
https://github.com/heroku/heroku-buildpack-python
And try to run this command in project's root terminal:
heroku buildpacks:set git://github.com/heroku/heroku-buildpack-python.git
and then update heroku with running below command:
git push heroku master