我决定把python3.4升级到python3.5
好像很麻烦,还是算了。。。。
2016年07月11日11:07:29
我觉得还可以再尝试一下
0,升级python3.4到python3.5
1)下载
https://www.python.org/downloads/
下载得到Python-3.5.2.tar.xz
2)编译安装
然后解压,找到README,执行
这就升级到3.5了
- senrsl@senrsl-T540p:~/python/Python-3.5.2$ ./configure
- senrsl@senrsl-T540p:~/python/Python-3.5.2$ make
- senrsl@senrsl-T540p:~/python/Python-3.5.2$ make test
- senrsl@senrsl-T540p:~/python/Python-3.5.2$ sudo make install
- 。。。。
- Collecting setuptools
- Collecting pip
- Installing collected packages: setuptools, pip
- Successfully installed pip-8.1.1 setuptools-20.10.1
- senrsl@senrsl-T540p:~/python/Python-3.5.2$ python --version
- Python 2.7.6
- senrsl@senrsl-T540p:~/python/Python-3.5.2$ python3 --version
- Python 3.5.2
- senrsl@senrsl-T540p:~/python/Python-3.5.2$
3)验证语法
升级
不错
- senrsl@senrsl-T540p:~/test/python3$ cp asyncio/test_asyncio_demo.py asyncio/test_async.py
- senrsl@senrsl-T540p:~/test/python3$ vi asyncio/test_async.py
- senrsl@senrsl-T540p:~/test/python3$ python3 asyncio/test_async.py
- hello,world!!!!!
- hello again!
- senrsl@senrsl-T540p:~/test/python3$ cat asyncio/test_async.py
- #!/usr/bin/env python3
- # -*- coding:utf-8 -*-
- import asyncio;
- async def hello():
- print("hello,world!!!!!");
- r = await asyncio.sleep(1);
- print("hello again!");
- loop = asyncio.get_event_loop();
- loop.run_until_complete(hello());
- loop.close();
- senrsl@senrsl-T540p:~/test/python3$
1,准备
1)环境准备
升级了python3.5.2之后,就提示升级pip3,然后安装异步框架aiohttp,前端模板引擎jinja2,mysql异步驱动 aiomysql.
不要在意那些细节
- senrsl@senrsl-T540p:~/test/python3/awesome-python3-webapp$ sudo pip3 install aiohttp
- [sudo] password for senrsl:
- The directory '/home/senrsl/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
- The directory '/home/senrsl/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
- Collecting aiohttp
- Downloading aiohttp-0.21.6.tar.gz (528kB)
- 100% |████████████████████████████████| 532kB 1.3MB/s
- Collecting chardet (from aiohttp)
- Downloading chardet-2.3.0.tar.gz (164kB)
- 100% |████████████████████████████████| 174kB 222kB/s
- Installing collected packages: chardet, aiohttp
- Running setup.py install for chardet ... done
- Running setup.py install for aiohttp ... done
- Successfully installed aiohttp-0.21.6 chardet-2.3.0
- You are using pip version 8.1.1, however version 8.1.2 is available.
- You should consider upgrading via the 'pip install --upgrade pip' command.
- senrsl@senrsl-T540p:~/test/python3/awesome-python3-webapp$ sudo pip3 install --upgrade pip
- The directory '/home/senrsl/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
- The directory '/home/senrsl/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
- Collecting pip
- Downloading pip-8.1.2-py2.py3-none-any.whl (1.2MB)
- 100% |████████████████████████████████| 1.2MB 917kB/s
- Installing collected packages: pip
- Found existing installation: pip 8.1.1
- Uninstalling pip-8.1.1:
- Successfully uninstalled pip-8.1.1
- Successfully installed pip-8.1.2
- senrsl@senrsl-T540p:~/test/python3/awesome-python3-webapp$
- senrsl@senrsl-T540p:~/test/python3/awesome-python3-webapp$ sudo pip3 install jinja2
- The directory '/home/senrsl/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
- The directory '/home/senrsl/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
- Collecting jinja2
- Downloading Jinja2-2.8-py2.py3-none-any.whl (263kB)
- 100% |████████████████████████████████| 266kB 1.2MB/s
- Collecting MarkupSafe (from jinja2)
- Downloading MarkupSafe-0.23.tar.gz
- Installing collected packages: MarkupSafe, jinja2
- Running setup.py install for MarkupSafe ... done
- Successfully installed MarkupSafe-0.23 jinja2-2.8
- senrsl@senrsl-T540p:~/test/python3/awesome-python3-webapp$
- senrsl@senrsl-T540p:~/test/python3/awesome-python3-webapp$ sudo pip3 install aiomysql
- The directory '/home/senrsl/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
- The directory '/home/senrsl/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
- Collecting aiomysql
- Downloading aiomysql-0.0.7.tar.gz (52kB)
- 100% |████████████████████████████████| 61kB 365kB/s
- Collecting PyMySQL<=0.6.7 (from aiomysql)
- Downloading PyMySQL-0.6.7-py2.py3-none-any.whl (69kB)
- 100% |████████████████████████████████| 71kB 851kB/s
- Installing collected packages: PyMySQL, aiomysql
- Running setup.py install for aiomysql ... done
- Successfully installed PyMySQL-0.6.7 aiomysql-0.0.7
- senrsl@senrsl-T540p:~/test/python3/awesome-python3-webapp$
2)项目结构
- senrsl@senrsl-T540p:~/test/python3/awesome-python3-webapp$ tree
- . 根
- ├── backup 备份目录
- ├── conf 配置文件
- ├── dist 打包目录
- ├── ios IOS app工程
- ├── LICENSE
- └── www web目录
- ├── static 静态文件
- └── templates 模板文件
- 8 directories, 0 files
- senrsl@senrsl-T540p:~/test/python3/awesome-python3-webapp$
2,Web App 开发
1)编写web app骨架
一个协程的异步http
- senrsl@senrsl-T540p:~/test/python3/awesome-python3-webapp$ cat www/app.py
- #!/usr/bin/env python3
- # -*- coding:utf-8 -*-
- import logging;logging.basicConfig(level=logging.INFO);
- import asyncio,os,json,time;
- from datetime import datetime;
- from aiohttp import web;
- def index(request):
- return web.Response(body=b"<h1>Awesome</h1>");
- @asyncio.coroutine
- def init(loop):
- app = web.Application(loop=loop);
- app.router.add_route("GET","/",index);
- srv = yield from loop.create_server(app.make_handler(),"127.0.0.1",9999);
- logging.info("server started at http://127.0.0.1:9999....");
- return srv;
- loop = asyncio.get_event_loop();
- loop.run_until_complete(init(loop));
- loop.run_forever();
- senrsl@senrsl-T540p:~/test/python3/awesome-python3-webapp$
1-3)使用eclipse
引入eclipse编辑器
下载,安装pydev插件
建个python项目发现多了.project跟.pydevproject俩配置文件
引入
2)编写ORM
①
2017年05月23日10:36:19
接近一年没动,多半是废了。。。。
--
senRsl
2016年07月09日13:47:50
2016年07月09日13:47:50
没有评论 :
发表评论