English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Flask Environment Configuration

Installing Flask usually requires Python 2.6or higher version. Although Flask and its dependencies are compatible with Python 3(Python 3.3The above version works well, but many Flask extensions do not support it properly. Therefore, but the official recommendation is to use Python 3.6+ Install Flask as mentioned above.

Install virtualenv

virtualenv is a virtual Python environment builder. It can help users create multiple Python environments in parallel. Therefore, it can avoid compatibility issues between different versions of libraries.

Use virtual environments to manage project dependencies in development and production.

What problems does virtual environment solve? The more Python projects you have, the more likely you need to use different versions of Python libraries, even different versions of Python itself. A newer version of a library in one project may break the compatibility of another project.

Virtual environments are independent groups of Python libraries, with each project having its own environment. The software packages installed in one project will not affect the software packages of other projects or the operating system.

If you are using:Python 2.x, then you can refer to the following installation development virtualenv .

The following command is on C:/pythonX/Install virtualenv under the scripts path, where X is the name of the Python version.

# Filename : example.py
# Copyright : 2020 By w3codebox
# Author by : www.oldtoolbag.com
# Date : 2020-08-08
pip install virtualenv

The output should be like this -

# Filename : example.py
# Copyright : 2020 By w3codebox
# Author by : www.oldtoolbag.com
# Date : 2020-08-08
Collecting virtualenv
   Downloading virtualenv-15.0.1-py2.py3-none-any.whl (1.8MB)
     100% |################################| 1.8MB 204kB/s
 Installing collected packages: virtualenv
 Successfully installed virtualenv-15.0.1

This command requires administrator privileges. In Linux/On Mac OS, you need to add sudo before pip. If you are on Windows, please log in as an administrator. On Ubuntu, virtualenv can be installed using its package manager.

# Filename : example.py
# Copyright : 2020 By w3codebox
# Author by : www.oldtoolbag.com
# Date : 2020-08-08
$ sudo apt-get install virtualenv

After installation, the new virtual environment will be created in the folder.

# Filename : example.py
# Copyright : 2020 By w3codebox
# Author by : www.oldtoolbag.com
# Date : 2020-08-08
mkdir newproj
 cd newproj
 virtualenv venv

To activate the corresponding environment, please in Linux/Use the following command on OS X -

# Filename : example.py
# Copyright : 2020 By w3codebox
# Author by : www.oldtoolbag.com
# Date : 2020-08-08
$ venv/bin/activate

On Windows, you can use the following command -

# Filename : example.py
# Copyright : 2020 By w3codebox
# Author by : www.oldtoolbag.com
# Date : 2020-08-08
venv\scripts\activate

Now prepare to install Flask in this environment.

# Filename : example.py
# Copyright : 2020 By w3codebox
# Author by : www.oldtoolbag.com
# Date : 2020-08-08
$ pip install Flask

The output should be like this -

# Filename : example.py
# Copyright : 2020 By w3codebox
# Author by : www.oldtoolbag.com
# Date : 2020-08-08
Collecting Flask
   Downloading Flask-0.10.1.tar.gz (544kB)
     100% |################################| 544kB 410kB/s
 Collecting Werkzeug>=0.7 (from Flask)
   Downloading Werkzeug-0.11.4-py2.py3-none-any.whl (305kB)
     100% |################################| 307kB 531kB/s
 Collecting Jinja2>=2.4 (from Flask)
   Downloading Jinja2-2.8-py2.py3-none-any.whl (263kB)
     100% |################################| 266kB 935kB/s
 Collecting itsdangerous>=0.21 (from Flask)
   Downloading itsdangerous-0.24.tar.gz (46kB)
     100% |################################| 49kB 1.6MB/s
 Collecting MarkupSafe (from Jinja2>=2.4->Flask)
   Downloading MarkupSafe-0.23.tar.gz
 Installing collected packages: Werkzeug, MarkupSafe, Jinja2, itsdangerous, Flask
   Running setup.py install for MarkupSafe
   Running setup.py install for itsdangerous
   Running setup.py install for Flask
 Successfully installed Flask-0.10.1 Jinja2-2.8 MarkupSafe-0.23 Werkzeug-0.11.4 itsdangerous-0.24

The above command can be run directly and does not require a virtual environment for system-wide installation.

The above content is mainly for Python 2.x version to install Flask.

Python 3bundled with the venv module to create a virtual environment. If you are using a modern version of Python, you can continue to read the next section.

Install Flask

In the activated environment, here with Window 10 + Python 3.6The environment is used as an installation demonstration. Install Flask using the following command:

# Filename : example.py
# Copyright : 2020 By w3codebox
# Author by : www.oldtoolbag.com
# Date : 2020-08-08
$ pip install Flask

Thus, the Flask installation is complete. In the next section, we will learn how to use Flask to create a simple web application.