现在我们来安装Flask:
Windows系统安装Flask
如果你的系统是Windows,那安装起来非常方便——pip install flask
Mac系统安装Flask
Mac安装Flask一般为了不影响Python本身的功能会先下载一个虚拟环境,命令如下:
- 第一步:
macbookdeMBP-2:~ macbook$ sudo easy_install virtualenv
- 第二步:
macbookdeMBP-2:~ macbook$ virtualenv venv
会看到:
New python executable in /Users/macbook/venv/bin/python
Installing setuptools, pip, wheel...done.
- 第三步:激活虚拟环境
macbookdeMBP-2:~ macbook$ pwd
/Users/macbook
macbookdeMBP-2:~ macbook$ cd /Users/macbook
macbookdeMBP-2:~ macbook$ ls
Applications Downloads Music PycharmProjects
Desktop Library Pictures VirtualBox VMs
Documents Movies Public venv
macbookdeMBP-2:~ macbook$ cd venv
macbookdeMBP-2:venv macbook$ ls
bin lib
include pip-selfcheck.json
macbookdeMBP-2:venv macbook$ cd bin
macbookdeMBP-2:bin macbook$ ls
activate easy_install-2.7 python-config
activate.csh pip python2
activate.fish pip2 python2.7
activate_this.py pip2.7 wheel
easy_install python
macbookdeMBP-2:bin macbook$ source activate
至此,虚拟机已经激活
- 第四步:在虚拟环境下安装Flask
先回到venv目录下,然后安装
(venv) macbookdeMBP-2:bin macbook$ cd ..
(venv) macbookdeMBP-2:venv macbook$ cd..
(venv) macbookdeMBP-2:~ macbook$ ls
Applications Downloads Music PycharmProjects
Desktop Library Pictures VirtualBox VMs
Documents Movies Public venv
(venv) macbookdeMBP-2:~ macbook$ cd venv
(venv) macbookdeMBP-2:venv macbook$ ls
bin lib
include pip-selfcheck.json
(venv) macbookdeMBP-2:venv macbook$ pip install flask
安装后看到:
Collecting flask
Downloading Flask-0.12.2-py2.py3-none-any.whl (83kB)
100% |████████████████████████████████| 92kB 134kB/s
Collecting Jinja2>=2.4 (from flask)
Downloading Jinja2-2.10-py2.py3-none-any.whl (126kB)
100% |████████████████████████████████| 133kB 214kB/s
Collecting Werkzeug>=0.7 (from flask)
Downloading Werkzeug-0.14.1-py2.py3-none-any.whl (322kB)
100% |████████████████████████████████| 327kB 211kB/s
Collecting click>=2.0 (from flask)
Downloading click-6.7-py2.py3-none-any.whl (71kB)
100% |████████████████████████████████| 71kB 233kB/s
Collecting itsdangerous>=0.21 (from flask)
Downloading itsdangerous-0.24.tar.gz (46kB)
100% |████████████████████████████████| 51kB 492kB/s
Collecting MarkupSafe>=0.23 (from Jinja2>=2.4->flask)
Downloading MarkupSafe-1.0.tar.gz
Building wheels for collected packages: itsdangerous, MarkupSafe
Running setup.py bdist_wheel for itsdangerous ... done
Stored in directory: /Users/macbook/Library/Caches/pip/wheels/fc/a8/66/24d655233c757e178d45dea2de22a04c6d92766abfb741129a
Running setup.py bdist_wheel for MarkupSafe ... done
Stored in directory: /Users/macbook/Library/Caches/pip/wheels/88/a7/30/e39a54a87bcbe25308fa3ca64e8ddc75d9b3e5afa21ee32d57
Successfully built itsdangerous MarkupSafe
Installing collected packages: MarkupSafe, Jinja2, Werkzeug, click, itsdangerous, flask
Successfully installed Jinja2-2.10 MarkupSafe-1.0 Werkzeug-0.14.1 click-6.7 flask-0.12.2 itsdangerous-0.24
至此,Flask安装完毕。
打开你的pycharm,新建项目,可以看到:
点击Create
就会生成Flask的模板了:
关于Mac安装Flask的方法大家可以看一下这篇帖子,或者自己百度一下:
http://blog.csdn.net/idoshi201109/article/details/79079572/
船长对Mac也不熟悉,说实话我自己安装的过程也是云里雾里,但是可以安装成功,具体原因我们不着急解释,毕竟影响不大,即使你不安装虚拟环境直接安装Flask也没有太大的影响(个人观点)。
如果你明白Mac安装虚拟环境和Flask的原理,还请不吝赐教!
微信公众号搜索“自动化测试实战”或扫描下方二维码添加关注~~~
原文地址:https://www.cnblogs.com/captainmeng/p/8478091.html