Installing Django on Ubuntu

Get started with the Python MVC framework that started it all

Stack

  • Ubuntu
  • Python 3
  • Pip 3
  • Nginx
  • Django (latest)

Install all Dependancies

We'll start with the obligatory update to ensure we're getting the latest packages.

apt-get update

Let's verify that Python 3 is is installed on your box.

python3 --version
Python 3.6.3

If Python 3 is not installed, go ahead and install it:

apt-get install python3

Next we'll need to download pip, python's package manager.

apt-get -y install python3-pip

Great, now let's go ahead and install Django. Find out what the latest distribution is by going here.

With the version number in hand, we'll install Django using pip:

pip3 install Django==1.11.7

Note that we're using pip3 here as opposed to pip.

Let's verify that you've installed Django correctly. Open your python3 shell and input the following:

>>> import django
>>> print(django.get_version())
1.11

If you receive an error along the lines of ModuleNotFoundError: No module named 'django', django was probably install on python2 as opposed to 3. Make sure that you used pip3 instead of pip to install django, and try again.

Why is this somewhat convoluted?

All major linux distributions come with python 2.7 pre-installed. Python2 is still critical to the core functionality of most linux distributions, therefore Python2 must be left intact and cannot be deleted or modified without suffering damage to the operating system.

Unfortunately, the python and pip commands will forever refer to Python 2 as a result, thus forcing Python 3 users to forever utilize the python3 and pip3 commands. This isn't that big of a deal, but is a common pitfall for those switching over to the light side.

Author image
New York City Website
Product manager turned engineer with an ongoing identity crisis. Breaks everything before learning best practices. Completely normal and emotionally stable.

Product manager turned engineer with an ongoing identity crisis. Breaks everything before learning best practices. Completely normal and emotionally stable.