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
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:
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:
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.
Next, we must choose where to install Anaconda. The default choice, our Home directory, if fine. Press the Enter key to continue.
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.
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.
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:
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
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.
6. Next, we need to activate our virtual environment. Enter the following command into the terminal to activate the environment:
source activate flask-env
You will see the prompt turn from this:
To having ‘(flask-env)’ before the prompt like this:
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
pip, the Python package management system, installs Flask and we are ready for Part 3 of the series.
Continue to Part 3