I'm trying to get Gunicorn to use Python3 for a Django app I want to make. I'm using Digital Ocean's Django image to get started. It comes with Django, Gunicorn, and Nginx installed and configured. The default Django project that comes with this image seems to work fine for Python 2.
I've apt-get
'ed these packages.
In order to try to avoid any problems, I've also done this.
I rm -rf
'ed the stock project and created a new one with django-admin.py startproject django_project
. django-admin.py
uses Python 3 (according to the shebang). Later, I use python3 manage.py startapp django_app
to create a new app.
At this point, everything works fine. Just like the default app. Then, in django_app/views.py
I do this and it breaks.
from django.shortcuts import render from django.http import HttpResponse def index(request): # Python 2 and 3 - works fine # print('PRINTING') # Python 3 only - crashes print(1, 2, end=' ') return HttpResponse("Hello, world! This is my first view.")
The error page says I'm using Python 2.7.6.
Okay, so then I thought I could install Gunicorn through pip for Python 3, so I do this.
But then I just end up with 502 Bad Gateway. When I do service gunicorn status
, I get gunicorn stop/waiting
. I tried service gunicorn restart
, but it still says gunicorn stop/waiting
.
I did a which gunicorn
and it's installed at /usr/local/bin/gunicorn
. Uhh... I'm not really sure what else I could try. Any help would be greatly appreciated. Thanks.
Python version 3.6. 5 (default in Ubuntu 18.04) Flask web framework version 1.0. 2.
Gunicorn 'Green Unicorn' is a Python WSGI HTTP Server for UNIX. It's a pre-fork worker model ported from Ruby's Unicorn project. The Gunicorn server is broadly compatible with various web frameworks, simply implemented, light on server resource usage, and fairly speedy.
This confirms that Gunicorn was started and able to serve your Django application. You can verify that the Gunicorn service is running by checking the status again: sudo systemctl status gunicorn.
Gunicorn is for a UNIX environment and is incompatible with Windows.
It seems that there's a package for this called gunicorn3 (this was tested on ubuntu) then running the following command should work and run gunicorn with python3: gunicorn3 --log-level debug --bind 0.0.0.0:30443 server:app This is the only answer that worked on Ubuntu, python 3.6. thanks.
[program:app-server] command = gunicorn app:app -b localhost:8000 directory = /home/www/app-server user = appuser That looks more like a supervisord configuration than a gunicorn config file. You need to install it using pip3 (or sometimes pip3.4 ).
Gunicorn is a popular application server for Python applications. It uses the Web Server Gateway Interface (WSGI), which defines how a web server communicates with and makes requests to a Python application.
I need both versions. The default one is gunicorn with pip2. What I did was I installed gunicorn with virtualenv using pip3 and looked at content of the file gunicorn under bin in the virtualenv folder, that says
It seems that there's a package for this called gunicorn3
(this was tested on ubuntu)
sudo apt-get install gunicorn3
then running the following command should work and run gunicorn with python3:
gunicorn3 --log-level debug --bind 0.0.0.0:30443 server:app
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With