How to Install Python 3.6+ and Django 2+ on Ubuntu 18.04 LTS

All right, let’s get started on installing the latest Python 3.6 which is our programming language and of course the web framework for Python which is the latest Django 2.1 as of this writing.

So, earlier we have installed our web server which is Ubuntu 18.04 LTS the latest version as of this writing, in case you missed the step-by-step guide on how to set up our Linux web server, you can check out at any point in time.

In Django installation guide itself which has a good installation guide for Linux based operating system.  So, are you ready? let’s open up once again our Console Access to begin the installation process.

Step 1:  Login to your Access Console and enter your root password.

In case you forgot this step on how to access your console, check back the server installation guide at this page.

After you successfully login with your root password, you can check first if Python 3.6+ has already been installed inside the package of Ubuntu 18.04 LTS version which is pre-installed already.

Execute this command from your console and press enter key.

1
2
3
root@localhost:~# python3 --version
Python 3.6.5
root@localhost:~#

As you can see, there is “Python 3.6.5” result from the command we’ve just given which means that there is a pre-installed Python 3.6.5 in our web server.  That’s good to know!

Just in case you didn’t see the result or didn’t return anything, you can just execute this command to install Python in our web server.

1
sudo apt-get install python3.6

Click “Yes” if it prompts you to proceed with the installation. By the way, have you notice the command “sudo apt-get install” is the standard command line for Ubuntu Linux distribution.

Installing Python is done, we want to test the Python shell command for further verification, try executing this command below and make some basic Python command for us to test it out.

1
2
3
4
5
6
7
root@localhost:~# python3
Python 3.6.6 (default, Sep 12 2018, 18:26:19)
[GCC 8.0.1 20180414 (experimental) [trunk revision 259383]] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 1+2
3
>>>

Great work!, the Python interpreter is now working on our web server, as you can see, I executed the simple computation for Python to calculate 1 + 2 and it returns 3.

Now, to exit the Python interpreter shell console, execute either of this command:  If you use exit() then press enter key or Ctrl-D from your keyboard.

1
exit()

That’s all for installing Python 3.6 for now, let’s proceed to install other required tools for us to install the latest Django.

Step 2.  Install PIP

What is PIP? pip is a package management system used to install and manage software packages written in Python.

According to https://en.wikipedia.org/wiki/Pip_(package_manager)

To verify if pip already installed, just execute this command “pip3 –version” and press enter key.

1
2
3
4
root@localhost:~# pip3 --version
Command 'pip3' not found, but can be installed with:
apt install python3-pip
root@localhost:~#

As you can see, we don’t have pip installed from our web server, so execute this command again and hit enter key.

1
apt install python3-pip

If prompt with “Do you want to continue? [Y/n], type ‘Y‘ and enter again to continue the installation.  If just in case you have something required for you to execute this command to update your Ubuntu distribution, please execute this command.

1
apt-get update

After successful update from your Ubuntu distribution, you can now proceed on re-executing this command to install pip3.

1
apt install python3-pip

Re-check your pip3 version by executing this command.

1
2
3
root@localhost:~# pip3 --version
pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.6)
root@localhost:~# ^

Success!, now pip3 has been successfully installed, we can now proceed with the rest of Python libraries and Django installation as well.

Step 3.  Install the latest Django.

To install the latest Django version, execute this command.

1
pip3 install Django

As of this writing, the latest Django version you can see from the result after executing the command above.  “Successfully installed Django-2.1.1 pytz-2018.5”  Great!

Next, to test out Django terminal and make sure Python can execute Django package.

1
2
3
4
5
6
7
8
root@localhost:~# python3
Python 3.6.6 (default, Sep 12 2018, 18:26:19)
[GCC 8.0.1 20180414 (experimental) [trunk revision 259383]] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> django.get_version()
'2.1.1'
>>>

That’s all, we’re done installing Python 3.6 and Django 2.1 for our development server.  So next time, we can now start focusing on our programming using Python and Django.

To help Filipino students to learn Python programming language with Django to enhance their capabilities in developing robust web-based applications with practical and direct to the point tutorials, step-by-step with actual information that I provided for you. Leave a comment below or email me at [email protected], thank you!