python包管理工具介绍  杨昆 y@zhihu.com
进入python的世界              Python如何管理它的软件?              egg是python组件的基本单位,              类似java中的jar包,ruby中              的gem...
egg的结构$ tree hellohello├── hello│ └── __init__.py├── hello.egg-info│ ├── PKG-INFO│ ├── SOURCES.txt│ ├── dependency_links.t...
包的依赖关系$ cat setup.pyfrom setuptools import setup, find_packagessetup(name=hello,    version=version,    ...    keywords=, ...
用namespace来组织你的包setup.py~~~~~~~~~~~                                $ tree fly.skelssetup(   ...                          f...
使用virtualenv和pip(sandbox) $ pip install -r requirements.txt(sandbox) $ cat requirements.txtsimplejsonredis==2.0.0-e svn+ht...
virtualenvwrapper● 创建虚拟环境  $ mkvirtualenv testenv● 在多个虚拟环境之间切换   $ lsvirtualenv   sandbox   testenv   $ workon sandbox   (...
virtualenv的问题● 多版本软件管理混乱● pip安装可能会失败, easy_install不够灵活● 重复下载,安装,在多项目及有c包的时候耗时较长● 还是需要手动构建环境
认识buildout● 从一个配置文件,可以构建整个环境, wirte once, deploy often。  类似于java中的maven● python包版本控制● 利用系统中已有的软件,无需重复下载安装● 各种recipe用于支持开发、...
运行buildout$ python bootstrap.py$ ./bin/buildout
pin versions[buildout]versions = versions[versions]tornado = 2.3sqlalchemy = 0.7.8hiredis = 0.1.1flask = 0.9
pin versions[buildout]extends = http://mirror.in.zhihu.com/buildout/0.1/version.cfgversions = versions
multiple configuration[buildout]extends = etc/base.cfg           etc/version.cfg         etc/supervisor.cfg
Install thirdparty software[zeromq]recipe = zc.recipe.cmmiurl = http://download.zeromq.org/zeromq-2.1.6.tar.gz
install thirdparty software[curl]recipe = hexagonit.recipe.cmmiurl = http://curl.haxx.se/download/curl-7.21.3.tar.bz2md5su...
私有pypi● localshop● pypiserver
Skeleton toolhttp://pypi.python.org/pypi/fly.skels
Upcoming SlideShare
Loading in …5
×

Python包管理工具介绍

845 views
576 views

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
845
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
7
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Python包管理工具介绍

  1. 1. python包管理工具介绍 杨昆 y@zhihu.com
  2. 2. 进入python的世界 Python如何管理它的软件? egg是python组件的基本单位, 类似java中的jar包,ruby中 的gem。 easy_install/pip 即是python的 apt-get。 $easy_install xxx $pip install xxx
  3. 3. egg的结构$ tree hellohello├── hello│ └── __init__.py├── hello.egg-info│ ├── PKG-INFO│ ├── SOURCES.txt│ ├── dependency_links.txt│ ├── entry_points.txt│ ├── not-zip-safe│ └── top_level.txt├── setup.cfg└── setup.py
  4. 4. 包的依赖关系$ cat setup.pyfrom setuptools import setup, find_packagessetup(name=hello, version=version, ... keywords=, author=, install_requires=[ tornado, mysql-python, cherrypy, ], ... )
  5. 5. 用namespace来组织你的包setup.py~~~~~~~~~~~ $ tree fly.skelssetup( ... fly.skels/ namespace_packages=[fly], ├── README.rst ├── fly) │ ├── __init__.py │ └── skels │ └── __init__.py ├── fly.skels.egg-info ├── setup.cfg └── setup.py
  6. 6. 使用virtualenv和pip(sandbox) $ pip install -r requirements.txt(sandbox) $ cat requirements.txtsimplejsonredis==2.0.0-e svn+http://svn.myproject.org/svn/MyProject/trunk#egg=MyProject-e git://git.myproject.org/MyProject.git#egg=MyProjecttornadosqlalchemy
  7. 7. virtualenvwrapper● 创建虚拟环境 $ mkvirtualenv testenv● 在多个虚拟环境之间切换 $ lsvirtualenv sandbox testenv $ workon sandbox (sandbox)$
  8. 8. virtualenv的问题● 多版本软件管理混乱● pip安装可能会失败, easy_install不够灵活● 重复下载,安装,在多项目及有c包的时候耗时较长● 还是需要手动构建环境
  9. 9. 认识buildout● 从一个配置文件,可以构建整个环境, wirte once, deploy often。 类似于java中的maven● python包版本控制● 利用系统中已有的软件,无需重复下载安装● 各种recipe用于支持开发、部署等
  10. 10. 运行buildout$ python bootstrap.py$ ./bin/buildout
  11. 11. pin versions[buildout]versions = versions[versions]tornado = 2.3sqlalchemy = 0.7.8hiredis = 0.1.1flask = 0.9
  12. 12. pin versions[buildout]extends = http://mirror.in.zhihu.com/buildout/0.1/version.cfgversions = versions
  13. 13. multiple configuration[buildout]extends = etc/base.cfg etc/version.cfg etc/supervisor.cfg
  14. 14. Install thirdparty software[zeromq]recipe = zc.recipe.cmmiurl = http://download.zeromq.org/zeromq-2.1.6.tar.gz
  15. 15. install thirdparty software[curl]recipe = hexagonit.recipe.cmmiurl = http://curl.haxx.se/download/curl-7.21.3.tar.bz2md5sum = 5b57fee22090b5c43a6886fdd35af2ceconfigure-options = --disable-ldap --disable-ldaps --disable-rtsp --disable-proxy --disable-dictenvironment = PATH=${pkgconfig:location}/bin:%(PATH)s PKG_CONFIG_PATH=${openssl:location}/lib/pkgconfig LDFLAGS=-Wl,-rpath -Wl,${zlib:location}/lib -Wl,-rpath -Wl,${openssl:location}/lib
  16. 16. 私有pypi● localshop● pypiserver
  17. 17. Skeleton toolhttp://pypi.python.org/pypi/fly.skels

×