[The Python] installed and running frame flask

As more and more of your Python project, you will find that different projects require different versions of Python libraries. Different versions of the same Python library may not be compatible.
Virtual environment can be installed for each project separate Python library that isolates the Python library between different projects, you can also isolate Python libraries between projects and operating system.

1. Python 2, installed virtualenv

ubuntu下:
apt-get install python-virtualenv
centos下:
yum install python-virtualenv

 

2. Create a virtual environment:

mkdir myproject
cd myproject
python3 -m venv venv

在python2下
python2 -m virtualenv venv

 

Once created project folder there is a folder venv

3. Activate the virtual environment

. venv/bin/activate

 

4. Installation Flask

pip install Flask

 

Error:
Could not the Find A Version at The Requirement that satisfies the Flask (from versions:)
No matching Distribution's found for the Flask
This is because a network problem, you need to accelerate domestic mirror source, such as watercress source

pip install flask -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com

5. Create hello.py

from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello, World!'

6. Run command flask

export FLASK_APP=hello.py
flask run --host=0.0.0.0

Guess you like

Origin www.cnblogs.com/taoshihan/p/12215296.html