本文地址:http://blog.youkuaiyun.com/spch2008/article/details/9082585
制作与安装
这篇文章讲的很详细,没有必要啰嗦啦。http://www.cnblogs.com/itech/archive/2011/02/13/1953268.html
setup.cfg
setup(
name = "spch2008",
version="0.1.1",
packages = find_packages(),
zip_safe = False,
description = "first egg",
author = "sunpch",
author_email = "sunpch@foxmail.com",
license = "GPL",
platforms = "Independant"
)
上述配置写在setup中过于庞大,如果继续添加参数,导致setup函数参数过于臃肿,此时,可以将配置参数写在配置文件中。
setup.cfg
[metadata]
name = spch2008
version = 0.1.1
zip_safe = False
description = first egg
author = sunpch
author-email = sunpch@foxmail.com
license = GPL
platforms = Independant
[files]
packages = spch2008
setup.py
from setuptools import setup
setup(
setup_requires=['d2to1>=0.2.10,<0.3'],
d2to1=True
)
创建目录文件spch2008/__init__.py
def hello():
print "info : Hello World!"
if __name__ == "__main__":
hello()
目录格式:
root@nova-controller:/home/sun/egg# ls
setup.cfg setup.py spch2008
制作egg并安装
root@nova-controller:/home/sun/egg# python setup.py bdist_egg
root@nova-controller:/home/sun/egg# ls
build d2to1-0.2.10-py2.7.egg dist setup.cfg setup.py spch2008 spch2008.egg-info
安装
root@nova-controller:/home/sun/egg# python setup.py install
creating /usr/local/lib/python2.7/dist-packages/spch2008-0.1.1-py2.7.egg
Extracting spch2008-0.1.1-py2.7.egg to /usr/local/lib/python2.7/dist-packages
由上可见,将egg信息拷贝到相应目录中。
运行
root@nova-controller:~# python -c "from spch2008 import hello; hello()"
info : Hello World!
注释
setup(
setup_requires=['d2to1>=0.2.10,<0.3'],
d2to1=True
)
为了安装本文制作的egg,需要安装d2to1(版本要大于等于0.2.10,但要小于0.3)。
d2to1=True表明需要使用d2to1库,d2to1用来解释setup.cfg文件中的内容。