狠狠撸

狠狠撸Share a Scribd company logo
? 2008 绿盟科技www.nsfocus.comnsfocus.com ? 2008 绿盟科技www.nsfocus.comnsfocus.com
Python 开发最佳实践
密级:内部使用
—— Python 开发环境包管理
好的开发环境意味着什么?
01.辫测迟丑辞苍.开发最佳实践
? Python 社区是一个变化非常快的社区
– 知识和工具都需要及时更新,跟进社区的变化
? Python 开发的最佳实践(推荐阅读)
– The Hitchhiker’s Guide to Python!
? 英文版:http://docs.python-guide.org/en/latest/
? Python 自身的包管理工具(推荐阅读)
– Python 套件管理程序介绍
? http://t.cn/zYdfQqV
– Python 的虚拟环境及多版本开发
? http://t.cn/zjOzu0y
– Hitchhiker’s Guide:
? Linux:http://t.cn/zYdfQqI
? Windows:http://t.cn/zYdfQqf
Python 的第三方包管理
pip + virtualenv + virtualenvwrapper 基本操作
? 知乎上的一个帖子 …… 神器?!
? 主要工具(Python 包管理三大利器)
– pip
? Python 的包管理工具,原有 easy_install 不再维护
? http://www.pip-installer.org/en/latest/
– virtualenv
? Python 的环境管理工具,隔离 Python 不同环境的影响
? http://www.virtualenv.org/en/latest/
– virtualenvwrapper
? virutalenv 的增强工具包,实现了很多很方便的工具
? http://virtualenvwrapper.readthedocs.org/en/latest/
pip + distribute
替代了
setuptools + easy_install
导出当前的第三方库
以 top 为例子
? 导出当前的第三方库清单
– pip freeze > top.txt
? 导出当前的第三方库安装包(包括依赖库)
– source /usr/local/bin/virtualenvwrapper.sh
(启用 virtualenvwrapper,非必须,可以写在 .bashrc 中)
– mkvirtualenv top.export
(创建一个干净的环境用于导出文件)
– mkdir export.packages
(准备一个导出文件用的目录)
– pip install -r top.txt -d export.packages
(下载所有第三方库)
从头创建一个开发环境
以 top 为例子
? 启用 virtualenvwrapper
(非必须,可以写在 .bashrc 中)
– source /usr/local/bin/virtualenvwrapper.sh
? 从 svn 获取最新代码
(非必须)
– svn co https://svn.lab.intra.nsfocus.com/svn/top/trunk
? 创建一个 virutalenv 环境
– mkvirutalenv top.brandnew
? 从生产环境的 pip 文件中恢复
– pip install -r top.txt
(top.txt 是从生产环境中导出的 python 包列表)
– pip freeze
(查看当前安装的 python 库)
复制/销毁一个现有的开发环境
以 top 为例子
? 复制现有的 virtualenv
– cpvirtualenv top.brandnew top.sandbox
(把 top.brandnew 这个环境复制到 top.sandbox)
– pip freeze
? 销毁现有的 virutalenv
– rmvirtualenv top.sandbox
回头看看我们的第叁方库管理
要实现
一个功能
搜寻
开源库
验证
是否可用
选定
引入代码库
开发 测试 上线
第三方库引入的示意图
? 初始化环境(运维人员)
– 标准的开发虚拟机模板(解决了系统库依赖)
? apt-get install ….
? svn co …/git clone …
? puppet …
– 创建生产环境的 virutalenv 作为标准环境(top.prodction)
? mkvirutalenv top.production
? mkdir top.production
? 把 top.production.txt 放到 top.production/top.production.txt
– 当前生产环境的第三方库(top.production.txt)
? workon top.production
? pip install -r top.production/top.production.txt
– 把上面的内容作为标准的初始化环境发布给开发人员和测试人员
要实现
一个功能
搜寻
开源库
验证
是否可用
选定
引入代码库
开发 测试 上线
0
? 沙盒环境中做实验(研发工程师)
– 从标准 virutalenv 创建沙盒环境用于实验
? cpvirtualenv top.production top.sandbox
– 在沙盒环境中做实验
? workon top.sandbox
? pip install …
– 删除并重建复沙盒(每次实验都不会受上一次实验影响)
? rmvirutalenv top.sandbox
? cpvirtualenv top.production top.sandbox
– 确定选择后,输出第三方库(清单和文件)
? pip freeze > top.sandbox.txt
? mkdir top.sandbox.packages
? pip install -r top.sandbox.txt -d top.sandbox.packages
– 把上面的内容作为标准的初始化环境发布给开发人员和测试人员
? 把 top.sandbox.txt 重命名为 top.release.txt 并作为代码一部分提交到代码库
? 把目录中 top.sandbox.packages 文件上传到指定服务器
要实现
一个功能
搜寻
开源库
验证
是否可用
选定
引入代码库
开发 测试 上线
0
1
? 在测试环境中做测试(测试工程师)
– 创建干净的沙盒
? mkvirtualenv top.testing
– 获取要测试的代码
? workon top.testing
? svn co …
? pip install -r top.release.txt
? 测试
要实现
一个功能
搜寻
开源库
验证
是否可用
选定
引入代码库
开发 测试 上线
0
1
2
? 在生产环境中部署(运维工程师)
– 创建干净的沙盒
? mkvirtualenv top.production
– 安装新代码
? workon top.production
? svn co …
? pip install -r top.release.txt
– 更新 production 环境
? 实际生产环境运行无问题
? 把 top.release.txt 重命名为 top.production.txt 提交
要实现
一个功能
搜寻
开源库
验证
是否可用
选定
引入代码库
开发 测试 上线
0
1
2 3
谢谢!

More Related Content

Viewers also liked (20)

Bottle - Python Web MicroframeworkBottle - Python Web Microframework
Bottle - Python Web Microframework
Markus Zapke-Gründemann
?
Django mongodb -djangoday_
Django mongodb -djangoday_Django mongodb -djangoday_
Django mongodb -djangoday_
WEBdeBS
?
Django e il Rap Elia Contini
Django e il Rap Elia ContiniDjango e il Rap Elia Contini
Django e il Rap Elia Contini
WEBdeBS
?
Digesting jQuery
Digesting jQueryDigesting jQuery
Digesting jQuery
Mindfire Solutions
?
User-centered open source
User-centered open sourceUser-centered open source
User-centered open source
Jacqueline Kazil
?
2016 py con2016_lightingtalk_php to python
2016 py con2016_lightingtalk_php to python2016 py con2016_lightingtalk_php to python
2016 py con2016_lightingtalk_php to python
Jiho Lee
?
Authentication & Authorization in ASPdotNet MVC
Authentication & Authorization in ASPdotNet MVCAuthentication & Authorization in ASPdotNet MVC
Authentication & Authorization in ASPdotNet MVC
Mindfire Solutions
?
2 × 3 = 6
2 × 3 = 62 × 3 = 6
2 × 3 = 6
Tzu-ping Chung
?
The Django Book Chapter 9 - Django Workshop - Taipei.py
The Django Book Chapter 9 - Django Workshop - Taipei.pyThe Django Book Chapter 9 - Django Workshop - Taipei.py
The Django Book Chapter 9 - Django Workshop - Taipei.py
Tzu-ping Chung
?
Html5 History-API
Html5 History-APIHtml5 History-API
Html5 History-API
Mindfire Solutions
?
PyClab.__init__(self)
PyClab.__init__(self)PyClab.__init__(self)
PyClab.__init__(self)
Tzu-ping Chung
?
EuroDjangoCon 2009 - Ein RückblickEuroDjangoCon 2009 - Ein Rückblick
EuroDjangoCon 2009 - Ein Rückblick
Markus Zapke-Gründemann
?
Load testing
Load testingLoad testing
Load testing
Mindfire Solutions
?
Super Advanced Python –act1
Super Advanced Python –act1Super Advanced Python –act1
Super Advanced Python –act1
Ke Wei Louis
?
Vim for Mere Mortals
Vim for Mere MortalsVim for Mere Mortals
Vim for Mere Mortals
Clayton Parker
?
Django-Queryset
Django-QuerysetDjango-Queryset
Django-Queryset
Mindfire Solutions
?
Website optimization
Website optimizationWebsite optimization
Website optimization
Mindfire Solutions
?
PythonBrasil[8] closingPythonBrasil[8] closing
PythonBrasil[8] closing
Tatiana Al-Chueyr
?
The Django Book, Chapter 16: django.contrib
The Django Book, Chapter 16: django.contribThe Django Book, Chapter 16: django.contrib
The Django Book, Chapter 16: django.contrib
Tzu-ping Chung
?
Django - The Web framework  for perfectionists with deadlinesDjango - The Web framework  for perfectionists with deadlines
Django - The Web framework for perfectionists with deadlines
Markus Zapke-Gründemann
?
Bottle - Python Web MicroframeworkBottle - Python Web Microframework
Bottle - Python Web Microframework
Markus Zapke-Gründemann
?
Django mongodb -djangoday_
Django mongodb -djangoday_Django mongodb -djangoday_
Django mongodb -djangoday_
WEBdeBS
?
Django e il Rap Elia Contini
Django e il Rap Elia ContiniDjango e il Rap Elia Contini
Django e il Rap Elia Contini
WEBdeBS
?
2016 py con2016_lightingtalk_php to python
2016 py con2016_lightingtalk_php to python2016 py con2016_lightingtalk_php to python
2016 py con2016_lightingtalk_php to python
Jiho Lee
?
Authentication & Authorization in ASPdotNet MVC
Authentication & Authorization in ASPdotNet MVCAuthentication & Authorization in ASPdotNet MVC
Authentication & Authorization in ASPdotNet MVC
Mindfire Solutions
?
The Django Book Chapter 9 - Django Workshop - Taipei.py
The Django Book Chapter 9 - Django Workshop - Taipei.pyThe Django Book Chapter 9 - Django Workshop - Taipei.py
The Django Book Chapter 9 - Django Workshop - Taipei.py
Tzu-ping Chung
?
EuroDjangoCon 2009 - Ein RückblickEuroDjangoCon 2009 - Ein Rückblick
EuroDjangoCon 2009 - Ein Rückblick
Markus Zapke-Gründemann
?
Super Advanced Python –act1
Super Advanced Python –act1Super Advanced Python –act1
Super Advanced Python –act1
Ke Wei Louis
?
PythonBrasil[8] closingPythonBrasil[8] closing
PythonBrasil[8] closing
Tatiana Al-Chueyr
?
The Django Book, Chapter 16: django.contrib
The Django Book, Chapter 16: django.contribThe Django Book, Chapter 16: django.contrib
The Django Book, Chapter 16: django.contrib
Tzu-ping Chung
?
Django - The Web framework  for perfectionists with deadlinesDjango - The Web framework  for perfectionists with deadlines
Django - The Web framework for perfectionists with deadlines
Markus Zapke-Gründemann
?

Similar to 01.辫测迟丑辞苍.开发最佳实践 (20)

Python First Class
Python First ClassPython First Class
Python First Class
Yao Zuo
?
Python beginner tutorial
Python beginner tutorialPython beginner tutorial
Python beginner tutorial
cri fan
?
用简单语言构建复杂系统
用简单语言构建复杂系统用简单语言构建复杂系统
用简单语言构建复杂系统
Leo Zhou
?
Ready Programmer One
Ready Programmer OneReady Programmer One
Ready Programmer One
flywindy
?
2 Python开发工具链
2 Python开发工具链2 Python开发工具链
2 Python开发工具链
March Liu
?
該怎麼樣(認真的)部署你的 Python Web 應用程式?
該怎麼樣(認真的)部署你的 Python Web 應用程式?該怎麼樣(認真的)部署你的 Python Web 應用程式?
該怎麼樣(認真的)部署你的 Python Web 應用程式?
Andy Dai
?
Summary conversatio-python-group-dalian
Summary conversatio-python-group-dalianSummary conversatio-python-group-dalian
Summary conversatio-python-group-dalian
wangyuanyi
?
构建网络工具箱
构建网络工具箱构建网络工具箱
构建网络工具箱
Lv Jian
?
Python 官方文件中文翻譯專案 - 探討翻譯專案的貢獻流程
Python 官方文件中文翻譯專案 - 探討翻譯專案的貢獻流程Python 官方文件中文翻譯專案 - 探討翻譯專案的貢獻流程
Python 官方文件中文翻譯專案 - 探討翻譯專案的貢獻流程
Wey-Han Liaw
?
如何,高效利用搜索引擎+构建网络工具箱
如何,高效利用搜索引擎+构建网络工具箱如何,高效利用搜索引擎+构建网络工具箱
如何,高效利用搜索引擎+构建网络工具箱
84zhu
?
Django step0
Django step0Django step0
Django step0
永昇 陳
?
Python 于 webgame 的应用
Python 于 webgame 的应用Python 于 webgame 的应用
Python 于 webgame 的应用
勇浩 赖
?
HPX台南讀書會-Axure RP基礎課程
HPX台南讀書會-Axure RP基礎課程HPX台南讀書會-Axure RP基礎課程
HPX台南讀書會-Axure RP基礎課程
Souyi Yang
?
瀏覽器開發與開源經驗 SITCON 2018
瀏覽器開發與開源經驗 SITCON  2018瀏覽器開發與開源經驗 SITCON  2018
瀏覽器開發與開源經驗 SITCON 2018
Anchi Liu
?
1 Python介绍
1 Python介绍1 Python介绍
1 Python介绍
March Liu
?
开源社区生生不息的创新土壤
开源社区生生不息的创新土壤开源社区生生不息的创新土壤
开源社区生生不息的创新土壤
Steven Cheng
?
Python 起步走
Python 起步走Python 起步走
Python 起步走
Justin Lin
?
Learn Django With ChatGPT
Learn Django With ChatGPTLearn Django With ChatGPT
Learn Django With ChatGPT
Ko Ko
?
Python 起步走
Python 起步走Python 起步走
Python 起步走
Justin Lin
?
Python summary
Python summaryPython summary
Python summary
cri fan
?
Python First Class
Python First ClassPython First Class
Python First Class
Yao Zuo
?
Python beginner tutorial
Python beginner tutorialPython beginner tutorial
Python beginner tutorial
cri fan
?
用简单语言构建复杂系统
用简单语言构建复杂系统用简单语言构建复杂系统
用简单语言构建复杂系统
Leo Zhou
?
Ready Programmer One
Ready Programmer OneReady Programmer One
Ready Programmer One
flywindy
?
2 Python开发工具链
2 Python开发工具链2 Python开发工具链
2 Python开发工具链
March Liu
?
該怎麼樣(認真的)部署你的 Python Web 應用程式?
該怎麼樣(認真的)部署你的 Python Web 應用程式?該怎麼樣(認真的)部署你的 Python Web 應用程式?
該怎麼樣(認真的)部署你的 Python Web 應用程式?
Andy Dai
?
Summary conversatio-python-group-dalian
Summary conversatio-python-group-dalianSummary conversatio-python-group-dalian
Summary conversatio-python-group-dalian
wangyuanyi
?
构建网络工具箱
构建网络工具箱构建网络工具箱
构建网络工具箱
Lv Jian
?
Python 官方文件中文翻譯專案 - 探討翻譯專案的貢獻流程
Python 官方文件中文翻譯專案 - 探討翻譯專案的貢獻流程Python 官方文件中文翻譯專案 - 探討翻譯專案的貢獻流程
Python 官方文件中文翻譯專案 - 探討翻譯專案的貢獻流程
Wey-Han Liaw
?
如何,高效利用搜索引擎+构建网络工具箱
如何,高效利用搜索引擎+构建网络工具箱如何,高效利用搜索引擎+构建网络工具箱
如何,高效利用搜索引擎+构建网络工具箱
84zhu
?
Python 于 webgame 的应用
Python 于 webgame 的应用Python 于 webgame 的应用
Python 于 webgame 的应用
勇浩 赖
?
HPX台南讀書會-Axure RP基礎課程
HPX台南讀書會-Axure RP基礎課程HPX台南讀書會-Axure RP基礎課程
HPX台南讀書會-Axure RP基礎課程
Souyi Yang
?
瀏覽器開發與開源經驗 SITCON 2018
瀏覽器開發與開源經驗 SITCON  2018瀏覽器開發與開源經驗 SITCON  2018
瀏覽器開發與開源經驗 SITCON 2018
Anchi Liu
?
开源社区生生不息的创新土壤
开源社区生生不息的创新土壤开源社区生生不息的创新土壤
开源社区生生不息的创新土壤
Steven Cheng
?
Learn Django With ChatGPT
Learn Django With ChatGPTLearn Django With ChatGPT
Learn Django With ChatGPT
Ko Ko
?
Python summary
Python summaryPython summary
Python summary
cri fan
?

More from Na Lee (6)

础谤耻产补-惭贰厂贬-解决方案.辫诲蹿
础谤耻产补-惭贰厂贬-解决方案.辫诲蹿础谤耻产补-惭贰厂贬-解决方案.辫诲蹿
础谤耻产补-惭贰厂贬-解决方案.辫诲蹿
Na Lee
?
火山引擎-飞连产物介绍.辫诲蹿
火山引擎-飞连产物介绍.辫诲蹿火山引擎-飞连产物介绍.辫诲蹿
火山引擎-飞连产物介绍.辫诲蹿
Na Lee
?
2007 年互联网基础设施安全的想法
2007 年互联网基础设施安全的想法2007 年互联网基础设施安全的想法
2007 年互联网基础设施安全的想法
Na Lee
?
02.辫测迟丑辞苍.开发最佳实践
02.辫测迟丑辞苍.开发最佳实践02.辫测迟丑辞苍.开发最佳实践
02.辫测迟丑辞苍.开发最佳实践
Na Lee
?
手机网络游戏平台
手机网络游戏平台手机网络游戏平台
手机网络游戏平台
Na Lee
?
淘宝连锁店
淘宝连锁店淘宝连锁店
淘宝连锁店
Na Lee
?
础谤耻产补-惭贰厂贬-解决方案.辫诲蹿
础谤耻产补-惭贰厂贬-解决方案.辫诲蹿础谤耻产补-惭贰厂贬-解决方案.辫诲蹿
础谤耻产补-惭贰厂贬-解决方案.辫诲蹿
Na Lee
?
火山引擎-飞连产物介绍.辫诲蹿
火山引擎-飞连产物介绍.辫诲蹿火山引擎-飞连产物介绍.辫诲蹿
火山引擎-飞连产物介绍.辫诲蹿
Na Lee
?
2007 年互联网基础设施安全的想法
2007 年互联网基础设施安全的想法2007 年互联网基础设施安全的想法
2007 年互联网基础设施安全的想法
Na Lee
?
02.辫测迟丑辞苍.开发最佳实践
02.辫测迟丑辞苍.开发最佳实践02.辫测迟丑辞苍.开发最佳实践
02.辫测迟丑辞苍.开发最佳实践
Na Lee
?
手机网络游戏平台
手机网络游戏平台手机网络游戏平台
手机网络游戏平台
Na Lee
?
淘宝连锁店
淘宝连锁店淘宝连锁店
淘宝连锁店
Na Lee
?

01.辫测迟丑辞苍.开发最佳实践