python egg包的制作与安装

本文地址:http://blog.csdn.net/spch2008/article/details/9082585


制作与安装

    这篇文章讲的很详细,没有必要啰嗦啦。http://www.cnblogs.com/itech/archive/2011/02/13/1953268.html


setup.cfg

[plain]  view plain copy print ?
  1. setup(      
  2.       name = "spch2008",  
  3.       version="0.1.1",  
  4.       packages = find_packages(),  
  5.       zip_safe = False,  
  6.   
  7.       description = "first egg",  
  8.       author = "sunpch",  
  9.       author_email = "sunpch@foxmail.com",  
  10.   
  11.       license = "GPL",  
  12.       platforms = "Independant"  
  13.       )   
        上述配置写在setup中过于庞大,如果继续添加参数,导致setup函数参数过于臃肿,此时,可以将配置参数写在配置文件中。

setup.cfg

[plain]  view plain copy print ?
  1. [metadata]  
  2. name = spch2008  
  3. version = 0.1.1  
  4. zip_safe = False  
  5.   
  6. description = first egg  
  7. author = sunpch  
  8. author-email = sunpch@foxmail.com  
  9.   
  10. license = GPL  
  11. platforms = Independant  
  12.   
  13. [files]  
  14. packages = spch2008  

setup.py
[python]  view plain copy print ?
  1. from setuptools import setup  
  2.   
  3. setup(  
  4.       setup_requires=['d2to1>=0.2.10,<0.3'],  
  5.       d2to1=True  
  6.       )  

创建目录文件spch2008/__init__.py
[plain]  view plain copy print ?
  1. def hello():  
  2.     print "info : Hello World!"  
  3.   
  4. if __name__ == "__main__":  
  5.     hello()  

目录格式:
[plain]  view plain copy print ?
  1. root@nova-controller:/home/sun/egg# ls  
  2. setup.cfg  setup.py  spch2008  

制作egg并安装
[plain]  view plain copy print ?
  1. root@nova-controller:/home/sun/egg# python setup.py bdist_egg  
  2. root@nova-controller:/home/sun/egg# ls  
  3. build  d2to1-0.2.10-py2.7.egg  dist  setup.cfg  setup.py  spch2008  spch2008.egg-info  
  4. root@nova-controller:/home/sun/egg# python setup.py install  

运行

[plain]  view plain copy print ?
  1. root@nova-controller:~# python -c "from spch2008 import hello; hello()"  
  2. info : Hello World!  

注释

[python]  view plain copy print ?
  1. setup(  
  2.       setup_requires=['d2to1>=0.2.10,<0.3'],  
  3.       d2to1=True  
  4.       )  
为了安装本文制作的egg,需要安装d2to1(版本要大于等于0.2.10,但要小于0.3)。

d2to1=True表明需要使用d2to1库,d2to1用来解释setup.cfg文件中的内容。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值