Skip to content

Instantly share code, notes, and snippets.

@tr00st
Last active May 19, 2022 14:40
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save tr00st/190ab4de62f9b23bea69 to your computer and use it in GitHub Desktop.
Save tr00st/190ab4de62f9b23bea69 to your computer and use it in GitHub Desktop.
DO NOT USE: OUT OF DATE & UNMAINTAINED - Python 3 upgrade script for the Django image on DigitalOcean
#!/bin/bash
#
# Copyright 2015 James Cheese
# You may do anything with this work that copyright law would normally
# restrict, so long as you retain the above notice(s) and this license
# in all redistributed copies and derived works. There is no warranty.
#
# Python 3 Upgrade for Django Droplet
# Will update the "Django on 14.04" Digital Ocean image.
# Run as root.
# Grab psycopg2 and pip
apt-get install python3-pip python3-psycopg2
# Remove the Python 2.7 version of gunicorn, so we can...
pip uninstall gunicorn
# Install the Python 3 version of gunicorn, and a couple of dependencies.
pip3 install gunicorn tornado django
# Sadly, at time of writing, gevent isn't Python 3 compatible... But tornado is!
# So, switch them out with a little sed magic
sed 's/worker_class = '\''gevent'\''/worker_class='\''tornado'\''/' /etc/gunicorn.d/gunicorn.py -i.orig
# Restart gunicorn to make the changes take effect...
service gunicorn restart
# And we're good!
@OriginalName75
Copy link

thanks !

@McKlatch
Copy link

Thank you so much. Beautiful how simple it was!
You should make it searchable in the digitalocean community (dont ask me, I dont know how).

@Ro0t-set
Copy link

Ro0t-set commented Dec 4, 2017

after this gunicorn script it does not work and gives me the error 502

@andriken
Copy link

don't run the script, now I can't fix the 502 nginx error

@plucena24
Copy link

You need to also update the nginx config files, which are all statically configured to point to the python2.7 site-packages directory.

root@tct001:/home/plucena# grep -R python /etc/nginx /etc/nginx/sites-enabled/django: alias /usr/lib/python2.7/dist-packages/django/contrib/admin/static/admin/; /etc/nginx/sites-available/django: alias /usr/lib/python2.7/dist-packages/django/contrib/admin/static/admin/;

This may be leading to at least some of the errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment