How to upgrade 1-click installer to Python 3 and newer version of Django?

March 19, 2016 5.8k views
Django Python One-Click Install Apps Deployment Ubuntu

So I am using the 1-click installer for Django, but found out is still using Python 2.7.6 and Django 1.6.1. Instead I want to use Python 3.x, but how do I do that?

I reviewed the article below, but again it focuses on Python 2.x:

https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-django-with-postgres-nginx-and-gunicorn

The 1-click article about Django had some tiny bit of Python 3 information in the comment, but not enough for me to figure out what to do:

https://www.digitalocean.com/community/tutorials/how-to-use-the-django-one-click-install-image

It is kind of baffling that there seems to be so little information about Python 3.x still and that so far I only found Heroku to have it ready to go. Any help would be much appreciated!

6 comments
8 Answers

You can use the alias command to customize this to strictly python3. In your server console:

  1. Type 'python --version'. It will tell you the version of python that responds to the 'python' command.
  2. Type 'python3 --version'. This will be the version you want to use.
  3. Type 'alias python=python3'. This changes the value of the python command to that of python3.
  4. Repeat step 1 to make sure it works.

We also want to make sure that the pip command is synced with the desired python version.

  1. Type 'sudo apt install python3-pip' and install it.
  2. Type 'alias pip=pip3'.
  3. Update pip by typing 'sudo pip install --upgrade pip'

Updating other libraries
NOTE: If you need to update/install packages globally, you will need to use the sudo command.

  1. Type 'pip list' to see what you want to upgrade.
  2. Use 'sudo pip ....' to accomplish what you need!
  • The above response is for virtual environments. Please note that the global library install is incorrect above as it will install a library to python2. See #2 below for correction.

    For the admin level (using sudo), use:

    1. 'sudo python3' instead of 'sudo python'
    2. 'sudo pip3' instead of 'sudo pip'.
    • I had to destroy my droplet after following these commands cause the actual alias 'pip' started giving an import error.
      Plus the question here is mainly how to change the environment of django from Python2 to Python3. Are you saying that we should re-install django on python3?
      If YES than should we also install the n-ginx web server as well for python3?

Non of the answers above make any sense to me. It would really streamline my development process if there was django + python3 droplet available from start. If anyone figures out how to switch 1-click django installer to Python 3, please post the answer here! I spent days searching for the answer and I'm not getting anywhere...

Also not getting anywhere with the 1 click install. It does all the wrong versions. Best is to build server from scratch until DO allows users to pick their versions. Also trying to change everything to python3 form the 1-click-install python2 always ends messy.

Following this question as well.
Be awesome for DO to allow user which versions to install for images.

Been trying to figure out how to do this. I'd love to upgrade the 1 click Django install to Django 2. @joelrinkoff does your solution upgrade the server's software and allow us to work with Django 2 without any other config etc?

Hi y’all...I just had this same issue, and though it certainly does away with the efficacy of the one-click thing, I was able to make this work by starting a new django project and then following these steps to make it the ‘real’ one:

https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-16-04

...of course, numerous of these steps are redundant, since the one-click already set up a job, but I followed them all and was able to get my site to point to the new one (which is using Python 3.5, all tucked away in its virtual environment like its supposed to be), without having to remove my droplet!

Sure would be a lot easier if there were a new option to cover this though...

by Justin Ellingwood
Django is a powerful web framework that can help you get your Python application or website off the ground. Django includes a simplified development server for testing your code locally, but for anything even slightly production related, a more secure and powerful web server...

Possibly a dangerous move, but what I did that finally worked was after making sure python3 and pip3 were installed:

Go to /usr/bin, remove python and pip, and create new links

ln -s python3 python

ln -s pip3 pip

Then pip install

  • django==1.11.15
  • gunicorn==19.7.1 important: this must be the exact version
  • gevent
  • netifaces

Finally, restart nginx and gunicorn. Hope I didn't forget anything.

Have another answer? Share your knowledge.