本文主要介绍flask环境搭建,搭建之前的python更新为3版本以及升级Python之后pip安装报错请参考pip安装报错
-
创建一个虚拟环境¶
创建一个项目文件夹,然后创建一个虚拟环境。创建完成后项目文件夹中会有一个 venv 文件夹:
[root@localhost ~]# ls
anaconda-ks.cfg my pip-1.5.4 pip-1.5.4.tar.gz
[root@localhost ~]# cd my/
[root@localhost my]# ls
Python-3.6.4 Python-3.6.4.tgz
[root@localhost my]# python -V //python版本为3.6.4
Python 3.6.4
[root@localhost my]# python -m venv venv
[root@localhost my]# ls
Python-3.6.4 Python-3.6.4.tgz venv //此处生成了一个虚拟venv
2. 激活虚拟环境
在开始工作前,先要激活相应的虚拟环境:
$ . venv/bin/activate
激活后,你的终端提示符会显示虚拟环境的名称。
[root@localhost my]# . venv/bin/activate
(venv) [root@localhost my]#
//激活后,终端提示符会显示虚拟环境的名称venv
3. 安装 Flask
在已激活的虚拟环境中可以使用如下命令安装 Flask:
$ pip install Flask
(venv) [root@localhost my]# pip install Flask
Collecting Flask
Downloading https://files.pythonhosted.org/packages/f2/28/2a03252dfb9ebf377f40fba6a7841b47083260bf8bd8e737b0c6952df83f/Flask-1.1.2-py2.py3-none-any.whl (94kB)
100% |?..?..?..?..?..?..?..?..?..?..?..?..?..?..?..?..| 102kB 238kB/s
Collecting click>=5.1 (from Flask)
Downloading https://files.pythonhosted.org/packages/d2/3d/fa76db83bf75c4f8d338c2fd15c8d33fdd7ad23a9b5e57eb6c5de26b430e/click-7.1.2-py2.py3-none-any.whl (82kB)
100% |?..?..?..?..?..?..?..?..?..?..?..?..?..?..?..?..| 92kB 144kB/s
Collecting Jinja2>=2.10.1 (from Flask)
Downloading https://files.pythonhosted.org/packages/30/9e/f663a2aa66a09d838042ae1a2c5659828bb9b41ea3a6efa20a20fd92b121/Jinja2-2.11.2-py2.py3-none-any.whl (125kB)
100% |?..?..?..?..?..?..?..?..?..?..?..?..?..?..?..?..| 133kB 47kB/s
Collecting Werkzeug>=0.15 (from Flask)
Downloading https://files.pythonhosted.org/packages/cc/94/5f7079a0e00bd6863ef8f1da638721e9da21e5bacee597595b318f71d62e/Werkzeug-1.0.1-py2.py3-none-any.whl (298kB)
100% |?..?..?..?..?..?..?..?..?..?..?..?..?..?..?..?..| 307kB 33kB/s
Collecting itsdangerous>=0.24 (from Flask)
Downloading https://files.pythonhosted.org/packages/76/ae/44b03b253d6fade317f32c24d100b3b35c2239807046a4c953c7b89fa49e/itsdangerous-1.1.0-py2.py3-none-any.whl
Collecting MarkupSafe>=0.23 (from Jinja2>=2.10.1->Flask)
Downloading https://files.pythonhosted.org/packages/b2/5f/23e0023be6bb885d00ffbefad2942bc51a620328ee910f64abe5a8d18dd1/MarkupSafe-1.1.1-cp36-cp36m-manylinux1_x86_64.whl
Installing collected packages: click, MarkupSafe, Jinja2, Werkzeug, itsdangerous, Flask
Successfully installed Flask-1.1.2 Jinja2-2.11.2 MarkupSafe-1.1.1 Werkzeug-1.0.1 click-7.1.2 itsdangerous-1.1.0
到这里,Flask安装已经完成。
关闭虚拟环境
(venv) [root@localhost scripts]# deactivate
[root@localhost scripts]#
即可