Installing Flask

Before initiating the programming process, you will need to install the required dependencies. Let's initiate the installation process by creating a virtual environment using virtual environment wrapper. It's one of the best practices to use a virtual environment while creating an application. The virtual environment wrapper is a tool which puts all the dependencies of the project in one place.

This practice will mitigate a lot of complications while dealing with different projects in your system. In our tutorial the installation and application development goes forward using Python version 2.7.

The following are the steps for setting up the environment:

  1. Install the virtual environment wrapper using pip. You may have to use sudo for administrative privileges:
    $ pip install virtualenvwrapper
    
  2. All the installation packages related to virtual environments are placed in one folder for the sake of convenience. Virtualenvwrapper identifies the directory using an environmental variable WORKON_HOME. So, set the environmental variable to ~/Envs or anything of your choice.
    $ export WORKON_HOME=~/Envs
    
  3. Create the WORKON_HOME directory using the following command if it doesn't exist on your local machine:
    $ mkdir -p $WORKON_HOME
    
  4. In order to use the utilities provided by the virtualenvwrapper, we need to activate the shell script virtualenvwrapper.sh as shown in the following lines. On Ubuntu machines, we can find this script in the /usr/local/bin location:
    $ source /usr/local/bin/virtualenvwrapper.sh
    
  5. For the sake of convenience, add the commands in steps 2 and 4 to your shell startup file to initialize and activate the virtualenvwrapper utilities at your terminal's startup.
  6. Now, use the mkvirtualenv command to create a new virtual environment for your project with the name survey. Once the survey environment is activated it gets displayed with the environment name in the closed braces before the shell prompt.
    $ mkvirtualenv survey
    New python executable in survey/bin/python
    Installing setuptools, pip...done.
    (survey) $
    

Installing required packages with pip

We are going to use Flask-SQLAlchemy in this project which is a Flask extension module that acts as an Object Relational Mapper (ORM) to interact with the database. We will also be using modules like requests, httpretty, beautifulsoup in the development of our survey application which we will be building in this tutorial.

Now install the following packages with your virtual environment activated:

(survey)~ $ pip install flask flask-sqlalchemy requests httpretty beautifulsoup4
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.148.113.229