Django will not upgrade. Gunicorn will not run virtualenv python interpreter.

July 11, 2017 312 views
Django Ubuntu

I decided to upgrade my Django site finally, making a jump from 1.6 to 1.11

Simply using the pip method didn't work because it throws an error about the old version of Django being owned by OS and no supplication to the sudo gods will change its mind about that.

Fine, I thought, I should be using virtualenv anyway. I'll just figure that out. So I create a virtualenv at /home/django/ahe/ahe and install django 1.11

I have a gunicorn daemon running via an upstart script so I also install gunicorn in the virtualenv. I alter the gunicorn.conf so that it calls this new gunicorn. I kill the old processes. New ones pop up immediately, but when I point my browser to my homepage the result is still running Django 1.6

I've tried to keep this simple, but I've actually spent hours trying different ways of solving this and I am at a loss. Any help is appreciated. Here's my gunicorn.conf:

start on (local-filesystems and net-device-up IFACE=eth0)
stop on runlevel [!12345]

# If the process quits unexpectadly trigger a respawn
respawn

setuid django
setgid django
chdir /home/django

script
    exec 2>>/tmp/upstartconfig.log
    set -x
    # Run gunicorn from the virtualenv
    cd /home/django/ahe/ahe
    source bin/activate

    exec /home/django/ahe/ahe/bin/gunicorn \
        --name=django_project \
        --pythonpath=django_project \
        --bind=127.0.0.1:9000 \
        --config /etc/gunicorn.d/gunicorn.py \
        django_project.wsgi:application
end script
2 comments
3 Answers

I am having the same issue. Spending way to much time on this

I previously deleted my answer (I briefly forgot about the edit button).

I've created several droplets in the past and upgrading django has always been a breeze however not sure what changed recently but it kept on defaulting to the django 1.8.7. It took me a while to figure it out but her was my solution.

Go to your root directory and run pip uninstall django

After that run django-admin --version. If this returns a version number like 1.8.7 or 1.1.1 etc, then run pip uninstall django again. Repeat this until you're sure there is no version of django on your server.

After you've verified that your server doesn't have django. Run pip install django. This will install the latest version of django on your server however you try to visit your server now you'll most likely get an error saying it can't find "django".

To fix this, go to your "django_project" folder. I'm sure you have a development version of this but just in case backup all the files on your production server and then delete this folder.

Head over to your root directory and go to your directory to where django is stored in your home folder by running cd /home/django

Run django-admin startproject django_project

You should have a djangoproject folder in our django folder now. Go into djangoproject.settings.py and in ALLOWED_HOSTS add the IP address/domain of your server.

Run sudo service gunicorn restart`

If you followed the steps above correctly then everything should be working. You'll also have to reconfigure your static files again in your settings.py.

Have another answer? Share your knowledge.