Python development environment to build Flask

Foreword

Before entering the installation, we must first get to know that a problem is this: why virtual environment?

  • Virtual environments primarily to ensure the unity of the environment, create a unique environment for python was too different applications.
  • As for the background development was Flask can create a virtual environment for application developers have to reptiles can create a virtual environment to avoid conflict between the environment.
  • To avoid an environmental cause was the installation package is too much, leading to environmental load slowly.

Installing the Virtual Environment

Virtual environment Gadget for 7 know are the following:

  • pipenv
  • virtualenv+pip
  • venv+pip
  • virtualenvwrapper
  • Poetry

First virtual environment recommended by Li Hui teacher I have been using the pipenv, but later encountered many problems in the course of the teacher and the parties also see Li Hui Wen chiefs of discouraging so here pipenv not recommend it to everyone, although it is just It came into use very convenient.

virtualenv + pip and venv + pip both basically the same use, the only difference is the way to create a virtual environment.
If you use Python3.3 and above, we recommend that you use the standard library built venv.

I use it here to tell you Python3.7 use venv + pip is
and how virtualenvwrapper and Poetry and have not yet played, after we are familiar with such as give you more to write a summary of the virtual environment.

1. Create a virtual environment

venv no need to install
Suppose we project called flask_example on the D drive, create a corresponding folder and then switch to the root directory such as:
Output
Enter the following command:

python -m venv flask-venv

step

Flask-venv which is the name of the virtual environment, but also as a virtual environment created folder name, you are free to modify (often used as a virtual environment venv or env name)

2. Activate the virtual environment

Enter the following command:

flask-venv\scripts\activate

Here Insert Picture Description

After activating the virtual environment, the command line prompt will be displayed before the name of the current virtual environment is as follows:
Output

3. Exit virtual environment

deactivate

4.pip management relies

command Explanation
pip install flask Install dependencies (Flask here is an example)
pip install -U flask Update dependence
pip show flask View details of a dependent (flask for example)
pip list List all dependent
pip freeze > requirements.txt Export virtual environment all depend on the package name
pip install -r requirements.txt All installation project depends module

Installation FLask framework

First, we must ensure that the virtual environment input in the case of activation of this command:

pip install flask

You can enter flask --version to see if the installation was successful

step
step

Reference Address:
problems preface the answer in reference to self: Why do we need to build a virtual environment

Published 29 original articles · won praise 19 · views 1315

Guess you like

Origin blog.csdn.net/s1156605343/article/details/104683321