【背景】
之前已经:
【记录】在ssh2可以登陆pcDuino后尝试去用VNC连接并操作pcDuino
现在接着去,用Python的flask去建立web服务器。
【折腾过程】
1.参考:
How to use Python to setup pcDuino as a web server | pcDuino
但是觉得其好像很繁琐的样子。
2.所以去官网:
Welcome | Flask (A Python Microframework)
去参考其:
Installation — Flask 0.10.1 documentation
去安装Flask,但是也觉得很烦。
3.所以直接去试试,在Lubuntu中去安装flask:
先打开Lubuntu中的终端LXTerminal:
然后启动终端之后:
4.再去安装flask:
结果很明显,Lubuntu中没有安装pip:
5.再去先安装pip:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | ubuntu@ubuntu:~$ sudo apt-get install python-pip Reading package lists... Done Building dependency tree Reading state information... Done The following extra packages will be installed: python-pkg-resources python-setuptools Suggested packages: python-distribute python-distribute-doc The following NEW packages will be installed: python-pip python-pkg-resources python-setuptools 0 upgraded, 3 newly installed, 0 to remove and 209 not upgraded. Need to get 599 kB of archives. After this operation, 1647 kB of additional disk space will be used. Do you want to continue [Y /n ]? y Get:1 http: //ports .ubuntu.com /ubuntu-ports/ precise /main python-pkg-resources all 0.6.24-1ubuntu1 [63.1 kB] Get:2 http: //ports .ubuntu.com /ubuntu-ports/ precise /main python-setuptools all 0.6.24-1ubuntu1 [441 kB] Get:3 http: //ports .ubuntu.com /ubuntu-ports/ precise /universe python-pip all 1.0-1build1 [95.1 kB] Fetched 599 kB in 3s (167 kB /s ) Selecting previously unselected package python-pkg-resources. (Reading database ... 63628 files and directories currently installed.) Unpacking python-pkg-resources (from ... /python-pkg-resources_0 .6.24-1ubuntu1_all.deb) ... Selecting previously unselected package python-setuptools. Unpacking python-setuptools (from ... /python-setuptools_0 .6.24-1ubuntu1_all.deb) ... Selecting previously unselected package python-pip. Unpacking python-pip (from ... /python-pip_1 .0-1build1_all.deb) ... Setting up python-pkg-resources (0.6.24-1ubuntu1) ... Setting up python-setuptools (0.6.24-1ubuntu1) ... Setting up python-pip (1.0-1build1) ... ubuntu@ubuntu:~$ |
如图:
6.然后再去用pip去安装flask:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | ubuntu@ubuntu:~$ sudo pip install flask Downloading /unpacking flask Downloading Flask-0.10.1. tar .gz (544Kb): 544Kb downloaded Running setup.py egg_info for package flask warning: no files found matching '*' under directory 'tests' 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' no previously-included directories found matching 'docs/_themes/.git' Downloading /unpacking Werkzeug>=0.7 (from flask) Cannot fetch index base URL http: //pypi .python.org /simple/ Downloading Werkzeug-0.9.4. tar .gz (1.1Mb): 1.1Mb downloaded Running setup.py egg_info for package Werkzeug warning: no files found matching '*' under directory 'werkzeug/debug/templates' warning: no files found matching '*' under directory 'tests' 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 Jinja2>=2.4 (from flask) Downloading Jinja2-2.7.1. tar .gz (377Kb): 377Kb downloaded Running setup.py egg_info for package Jinja2 warning: no files found matching '*' under directory 'custom_fixers' warning: no previously-included files matching '*' found under directory 'docs/_build' warning: no previously-included files matching '*.pyc' found under directory 'jinja2' warning: no previously-included files matching '*.pyc' found under directory 'docs' warning: no previously-included files matching '*.pyo' found under directory 'jinja2' warning: no previously-included files matching '*.pyo' found under directory 'docs' Downloading /unpacking itsdangerous>=0.21 (from flask) Downloading itsdangerous-0.23. 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 markupsafe (from Jinja2>=2.4->flask) Downloading MarkupSafe-0.18. tar .gz Running setup.py egg_info for package markupsafe Installing collected packages: flask, Werkzeug, Jinja2, itsdangerous, markupsafe Running setup.py install for flask warning: no files found matching '*' under directory 'tests' 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' no previously-included directories found matching 'docs/_themes/.git' Running setup.py install for Werkzeug warning: no files found matching '*' under directory 'werkzeug/debug/templates' warning: no files found matching '*' under directory 'tests' 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 Jinja2 warning: no files found matching '*' under directory 'custom_fixers' warning: no previously-included files matching '*' found under directory 'docs/_build' warning: no previously-included files matching '*.pyc' found under directory 'jinja2' warning: no previously-included files matching '*.pyc' found under directory 'docs' warning: no previously-included files matching '*.pyo' found under directory 'jinja2' warning: no previously-included files matching '*.pyo' found under directory 'docs' Running setup.py install for itsdangerous warning: no previously-included files matching '*' found under directory 'docs/_build' Running setup.py install for markupsafe building 'markupsafe._speedups' extension gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I /usr/include/python2 .7 -c markupsafe /_speedups .c -o build /temp .linux-armv7l-2.7 /markupsafe/_speedups .o markupsafe /_speedups .c:12:20: fatal error: Python.h: No such file or directory compilation terminated. ========================================================================== 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 markupsafe Cleaning up... ubuntu@ubuntu:~$ |
如图:
7.然后再去参考官网去写测试代码:
启动LeafPad
拷贝代码:
1 2 3 4 5 6 7 8 9 | from flask import Flask app = Flask(__name__) @app .route( "/" ) def hello(): return "Demo webserver using python flask in Lubuntu pcDunino by Crifan Li" if __name__ = = "__main__" : app.run(host = '0.0.0.0' , port = 80 , debug = True ) |
然后用Ctrl+V去粘贴代码到Leafpad中:
然后另存为:
然后新建一个叫做develop的文件夹:
然后输入回车,进入该文件夹,然后输入保存的文件名:demoWebserverViaFlask.py,然后再点Save保存:
8.然后回到终端中,切换到对应的develop文件夹,则ls可以看到对应的文件:
然后再去运行:
9.在主机端Win7中,能访问到这个服务器之前,先去确定其pcDuino的ip是多少
可见,是:
192.168.1.107
所以,在Win7中,用(火狐)浏览器去访问此地址:
说明的确用Python的Flask建立的Web服务器,的确可以正常工作了。
对应的,可以看到终端中的输出:
显示出对应的网页的访问。
【总结】
至此,在pcDuino的Lubuntu上,用Python的Flask去建立一个最简单的Web服务器,就完成了。
其中可见:
主要是对于在Ubuntu系统上,去安装Flask,建立Web服务器,相关的操作流程。
其本身,和pcDuino,倒是关系不大。
但是,这也说明了,此处,可以把pcDuino当做一台服务器,可以用此服务器,去做你想要的各种各样的事情了。