The Ultimate Guide to Creating a Flask Web Development Environment on Ubuntu 18.04 LTS

May 23, 2018
The Ultimate Guide to Creating a Flask Web Development Environment on Ubuntu 18.04 LTS

“The Ultimate Guide to Creating a Flask Web Development Environment on Ubuntu 18.04 LTS” covers the entire process of creating a productive Flask web development environment on a fresh Ubuntu 18.04 LTS install. Flask is a microframework that is used when Python is the server-side language in a web application. Flask is a popular choice for web applications because, unlike Django, it is incredibly light weight. Flask ships with the essentials needed to get up and running and nothing more. This approach allows the developer to have full control and install only what is needed for a particular application by way of extensions. Flask’s incorporated Jinja2 template engine offers the significant advantage of performing logic operations within views, resulting in truly dynamic web pages. This tutorial assumes that your Ubuntu system was installed in a similar manner to the previous tutorial, "The Ultimate Guide to Installing Ubuntu 18.04 in VirtualBox."

1. Since we are starting with a fresh install of Ubuntu 18.04, the first thing that we need to do to prepare our Flask web development environment is update our machine. Open a terminal and enter the following command:


sudo apt-get update && sudo apt-get upgrade -y

The Ultimate Guide to Creating a Flask Web Development Environment on Ubuntu 18.04 LTS

Enter the root or sudo password that you chose when you installed the machine. The machine will take a few minutes to update and upgrade packages since it is a fresh install.

2. Now that our Ubuntu machine is updated, we need to install Anaconda. Anaconda is an package management and deployment solution for both Python and R programming languages and is widely used in the fields of scientific computing, machine learning, and data science. Anaconda will allow us to create unique virtual environments for each Python or Flask application on our Ubuntu machine. A local copy of Python and many popular packages are installed into each virtual environment making each virtual environment totally independent. This has many obvious benefits for development but offers significant advantages with deployment as well. In your terminal, enter the following command to download Anaconda to your Ubuntu machine:


wget https://repo.anaconda.com/archive/Anaconda3-5.1.0-Linux-x86_64.sh

The Ultimate Guide to Creating a Flask Web Development Environment on Ubuntu 18.04 LTS

3. After a few moments, Anaconda is downloaded and we are ready to install it. Enter the following command in the terminal to install Anaconda:


bash Anaconda3-5.1.0-Linux-x86_64.sh

The Ultimate Guide to Creating a Flask Web Development Environment on Ubuntu 18.04 LTS

The installer begins and we are presented with a prompt informing us that we must review the license. Go ahead and press Enter. Now we must press the Enter key a few times to scroll through the license. At the end of the license, we must accept the terms of the license. Type “yes” to accept and press the Enter key.

The Ultimate Guide to Creating a Flask Web Development Environment on Ubuntu 18.04 LTS

Next, we must choose where to install Anaconda. The default choice, our Home directory, if fine. Press the Enter key to continue.

The Ultimate Guide to Creating a Flask Web Development Environment on Ubuntu 18.04 LTS

Anaconda will finish installing after a few minutes. When it finishes, we will be asked if we want to add Anaconda to PATH. The default is set to no, but we need to type “yes” into the prompt. This will save us some headaches in the future.

The Ultimate Guide to Creating a Flask Web Development Environment on Ubuntu 18.04 LTS

Conveniently enough, we are now asked if we would like to install Microsoft VSCode, which we do. Go ahead and type “yes” into the prompt and press the Enter key.

The Ultimate Guide to Creating a Flask Web Development Environment on Ubuntu 18.04 LTS

4. Now that both Anaconda and Microsoft VSCode are installed, we will need to reboot our machine for the changes to PATH to be activated. Enter the following command into the terminal to reboot your Ubuntu machine:

sudo reboot

The Ultimate Guide to Creating a Flask Web Development Environment on Ubuntu 18.04 LTS

5. When the machine is rebooted and you are logged in, we can create our first virtual environment. Launch a terminal and enter the following command to create the environment:


conda create –name flask-env python=3

The Ultimate Guide to Creating a Flask Web Development Environment on Ubuntu 18.04 LTS

This will begin creating a virtual environment based on Python 3.5 and with the name “flask-env.” After locating all of the packages needed for our virtual environment, we are asked if we want to proceed. Type “y” and press Enter.

The Ultimate Guide to Creating a Flask Web Development Environment on Ubuntu 18.04 LTS

6. Next, we need to activate our virtual environment. Enter the following command into the terminal to activate the environment:

source activate flask-env

The Ultimate Guide to Creating a Flask Web Development Environment on Ubuntu 18.04 LTS

You will see the prompt turn from this:

The Ultimate Guide to Creating a Flask Web Development Environment on Ubuntu 18.04 LTS

To having ‘(flask-env)’ before the prompt like this:

The Ultimate Guide to Creating a Flask Web Development Environment on Ubuntu 18.04 LTS

The addition to the front of the prompt lets us know that we are operating in our virtual environment. Any packages or extensions that we install for our flask application will now be stored in our virtual environment instead of our Ubuntu machine.

7. Finally, install Flask into our virtual environment by entering the following command into the terminal:

pip install flask
The Ultimate Guide to Creating a Flask Web Development Environment on Ubuntu 18.04 LTS

pip, the Python package management system, installs Flask and we are ready for Part 3 of the series.
Continue to Part 3