marty001 发表于 2018-8-8 10:05:48

Python flask 框架搭建

  系统环境:CentOS7,Python版本:2.7.5

[*]  检查是否安装了virtualenv
  virtualenv -version
  没有显示版本信息,说明没有安装virtualenv.
  安装virtualenv的作用是使用程序运行能使用虚拟环境。
  # yum install python-virtualenv
  Loaded plugins: fastestmirror
  base                                                                                                                                             | 3.6 kB00:00:00
  epel/x86_64/metalink                                                                                                                           | 5.2 kB00:00:00
  epel                                                                                                                                             | 4.7 kB00:00:00
  extras                                                                                                                                           | 3.4 kB00:00:00
  updates                                                                                                                                          | 3.4 kB00:00:00
  (1/3): extras/7/x86_64/primary_db                                                                                                                | 130 kB00:00:00
  (2/3): epel/x86_64/updateinfo                                                                                                                  | 848 kB00:00:10
  (3/3): epel/x86_64/primary_db                                                                                                                  | 6.1 MB00:00:17
  Loading mirror speeds from cached hostfile
  * base: mirrors.aliyun.com
  * epel: mirrors.ustc.edu.cn
  * extras: mirrors.btte.net
  * updates: mirrors.aliyun.com
  Resolving Dependencies
  --> Running transaction check
  ---> Package python-virtualenv.noarch 0:1.10.1-4.el7 will be installed
  --> Processing Dependency: python-setuptools for package: python-virtualenv-1.10.1-4.el7.noarch
  --> Running transaction check
  ---> Package python-setuptools.noarch 0:0.9.8-7.el7 will be installed
  --> Processing Dependency: python-backports-ssl_match_hostname for package: python-setuptools-0.9.8-7.el7.noarch
  --> Running transaction check
  ---> Package python-backports-ssl_match_hostname.noarch 0:3.4.0.2-4.el7 will be installed
  --> Processing Dependency: python-backports for package: python-backports-ssl_match_hostname-3.4.0.2-4.el7.noarch
  --> Running transaction check
  ---> Package python-backports.x86_64 0:1.0-8.el7 will be installed
  --> Finished Dependency Resolution
  Dependencies Resolved
  ========================================================================================================================================================================
  Package                                                   Arch                           Version                                  Repository                  Size
  ========================================================================================================================================================================
  Installing:
  python-virtualenv                                           noarch                         1.10.1-4.el7                           base                         1.2 M
  Installing for dependencies:
  python-backports                                          x86_64                         1.0-8.el7                              base                         5.8 k
  python-backports-ssl_match_hostname                         noarch                         3.4.0.2-4.el7                            base                        12 k
  python-setuptools                                           noarch                         0.9.8-7.el7                              base                         397 k
  Transaction Summary
  ========================================================================================================================================================================
  Install1 Package (+3 Dependent packages)

  Total download>
  Installed>  Is this ok : y
  Downloading packages:
  (1/4): python-backports-1.0-8.el7.x86_64.rpm                                                                                                   | 5.8 kB00:00:00
  (2/4): python-backports-ssl_match_hostname-3.4.0.2-4.el7.noarch.rpm                                                                              |12 kB00:00:00
  (3/4): python-setuptools-0.9.8-7.el7.noarch.rpm                                                                                                | 397 kB00:00:00
  python-virtualenv-1.10.1-4.el7 FAILED
  http://mirrors.nju.edu.cn/centos/7.4.1708/os/x86_64/Packages/python-virtualenv-1.10.1-4.el7.noarch.rpm: Timeout on http://mirrors.nju.edu.cn/centos/7.4.1708/os/x86_64/Packages/python-virtualenv-1.10.1-4.el7.noarch.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
  Trying other mirror.
  (4/4): python-virtualenv-1.10.1-4.el7.noarch.rpm                                                                                                 | 1.2 MB00:00:01
  ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  Total                                                                                                                                    49 kB/s | 1.6 MB00:00:34
  Running transaction check
  Running transaction test
  Transaction test succeeded
  Running transaction
  Installing : python-backports-1.0-8.el7.x86_64                                                                                                                  1/4
  Installing : python-backports-ssl_match_hostname-3.4.0.2-4.el7.noarch                                                                                             2/4
  Installing : python-setuptools-0.9.8-7.el7.noarch                                                                                                               3/4
  Installing : python-virtualenv-1.10.1-4.el7.noarch                                                                                                                4/4
  Verifying: python-virtualenv-1.10.1-4.el7.noarch                                                                                                                1/4
  Verifying: python-setuptools-0.9.8-7.el7.noarch                                                                                                               2/4
  Verifying: python-backports-1.0-8.el7.x86_64                                                                                                                  3/4
  Verifying: python-backports-ssl_match_hostname-3.4.0.2-4.el7.noarch                                                                                             4/4
  Installed:
  python-virtualenv.noarch 0:1.10.1-4.el7
  Dependency Installed:
  python-backports.x86_64 0:1.0-8.el7            python-backports-ssl_match_hostname.noarch 0:3.4.0.2-4.el7            python-setuptools.noarch 0:0.9.8-7.el7
  Complete!
  2.创建目录/flask
  # cd /flask/
  3.# virtualenv venv
  # virtualenv venv
  New python executable in venv/bin/python
  Installing Setuptools..............................................................................................................................................................................................................................done.
  Installing Pip.....................................................................................................................................................................................................................................................................................................................................done.
  4.激活创建的虚拟环境
  # source venv/bin/activate
  屏幕回显出现变化
  (venv)#
  5.安装flask
  (venv)# pip install flask
  Downloading/unpacking flask
  Downloading Flask-0.12.2.tar.gz (548kB): 548kB downloaded
  Running setup.py egg_info for package flask
  warning: no previously-included files matching '*.py' found anywhere in distribution
  no previously-included directories found matching 'docs/_build'
  no previously-included directories found matching 'docs/_themes'
  Downloading/unpacking Werkzeug>=0.7 (from flask)
  Downloading Werkzeug-0.12.2.tar.gz (1.2MB): 1.2MB downloaded
  Running setup.py egg_info for package Werkzeug
  no previously-included directories found matching 'docs/_build'
  no previously-included directories found matching 'docs/_themes'
  warning: no previously-included files matching '*.py' found anywhere in distribution
  warning: no previously-included files matching '__pycache__' found anywhere in distribution
  warning: no previously-included files matching '*.so' found anywhere in distribution
  warning: no previously-included files matching '*.pyd' found anywhere in distribution
  Downloading/unpacking Jinja2>=2.4 (from flask)
  Downloading Jinja2-2.10.tar.gz (261kB): 261kB downloaded
  Running setup.py egg_info for package Jinja2
  warning: no previously-included files matching '*.py' found anywhere in distribution
  no previously-included directories found matching 'docs/_build'
  Downloading/unpacking itsdangerous>=0.21 (from flask)
  Downloading itsdangerous-0.24.tar.gz (46kB): 46kB downloaded
  Running setup.py egg_info for package itsdangerous
  warning: no previously-included files matching '*' found under directory 'docs/_build'
  Downloading/unpacking click>=2.0 (from flask)
  Downloading click-6.7.tar.gz (279kB): 279kB downloaded
  Running setup.py egg_info for package click
  warning: no previously-included files matching '*.pyc' found under directory 'docs'
  warning: no previously-included files matching '*.pyo' found under directory 'docs'
  warning: no previously-included files matching '*.pyc' found under directory 'tests'
  warning: no previously-included files matching '*.pyo' found under directory 'tests'
  warning: no previously-included files matching '*.pyc' found under directory 'examples'
  warning: no previously-included files matching '*.pyo' found under directory 'examples'
  no previously-included directories found matching 'docs/_build'
  Downloading/unpacking MarkupSafe>=0.23 (from Jinja2>=2.4->flask)
  Downloading MarkupSafe-1.0.tar.gz
  Running setup.py egg_info for package MarkupSafe
  Installing collected packages: flask, Werkzeug, Jinja2, itsdangerous, click, MarkupSafe
  Running setup.py install for flask
  warning: no previously-included files matching '*.py' found anywhere in distribution
  no previously-included directories found matching 'docs/_build'
  no previously-included directories found matching 'docs/_themes'
  Installing flask script to /flask/venv/bin
  Running setup.py install for Werkzeug
  no previously-included directories found matching 'docs/_build'
  no previously-included directories found matching 'docs/_themes'
  warning: no previously-included files matching '*.py' found anywhere in distribution
  warning: no previously-included files matching '__pycache__' found anywhere in distribution
  warning: no previously-included files matching '*.so' found anywhere in distribution
  warning: no previously-included files matching '*.pyd' found anywhere in distribution
  Running setup.py install for Jinja2
  warning: no previously-included files matching '*.py' found anywhere in distribution
  no previously-included directories found matching 'docs/_build'
  File "/flask/venv/lib/python2.7/site-packages/jinja2/asyncfilters.py", line 7
  async def auto_to_seq(value):
  ^
  SyntaxError: invalid syntax
  File "/flask/venv/lib/python2.7/site-packages/jinja2/asyncsupport.py", line 22
  async def concat_async(async_gen):
  ^
  SyntaxError: invalid syntax
  Running setup.py install for itsdangerous
  warning: no previously-included files matching '*' found under directory 'docs/_build'
  Running setup.py install for click
  warning: no previously-included files matching '*.pyc' found under directory 'docs'
  warning: no previously-included files matching '*.pyo' found under directory 'docs'
  warning: no previously-included files matching '*.pyc' found under directory 'tests'
  warning: no previously-included files matching '*.pyo' found under directory 'tests'
  warning: no previously-included files matching '*.pyc' found under directory 'examples'
  warning: no previously-included files matching '*.pyo' found under directory 'examples'
  no previously-included directories found matching 'docs/_build'
  Running setup.py install for MarkupSafe
  building 'markupsafe._speedups' extension
  gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/usr/include/python2.7 -c markupsafe/_speedups.c -o build/temp.linux-x86_64-2.7/markupsafe/_speedups.o
  unable to execute gcc: No such file or directory
  ==========================================================================
  WARNING: The C extension could not be compiled, speedups are not enabled.
  Failure information, if any, is above.
  Retrying the build without the C extension now.
  ==========================================================================
  WARNING: The C extension could not be compiled, speedups are not enabled.
  Plain-Python installation succeeded.
  ==========================================================================
  Successfully installed flask Werkzeug Jinja2 itsdangerous click MarkupSafe
  Cleaning up...
  #有时间研究为什么会出现这么多WARNING
  6.验证是否安装成功。
  (venv)# python
  Python 2.7.5 (default, Aug4 2017, 00:39:18)
   on linux2
  Type "help", "copyright", "credits" or "license" for more information.
  >>> import flask
  >>> exit()
页: [1]
查看完整版本: Python flask 框架搭建