您的位置:首页 > 编程语言 > Python开发

python egg包的制作与安装

2013-07-18 08:35 295 查看
本文地址:/content/684628.html

制作与安装

这篇文章讲的很详细,没有必要啰嗦啦。/article/4665466.html



setup.cfg

[plain] view
plaincopyprint?

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

[plain] view
plaincopyprint?

[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

[python] view
plaincopyprint?

from setuptools import setup

setup(

setup_requires=['d2to1>=0.2.10,<0.3'],

d2to1=True

)

创建目录文件spch2008/__init__.py

[plain] view
plaincopyprint?

def hello():

print "info : Hello World!"

if __name__ == "__main__":

hello()

目录格式:

[plain] view
plaincopyprint?

root@nova-controller:/home/sun/egg# ls

setup.cfg setup.py spch2008

制作egg并安装

[plain] view
plaincopyprint?

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

运行

[plain] view
plaincopyprint?

root@nova-controller:~# python -c "from spch2008 import hello; hello()"

info : Hello World!

注释

[python] view
plaincopyprint?

setup(

setup_requires=['d2to1>=0.2.10,<0.3'],

d2to1=True

)

为了安装本文制作的egg,需要安装d2to1(版本要大于等于0.2.10,但要小于0.3)。

d2to1=True表明需要使用d2to1库,d2to1用来解释setup.cfg文件中的内容。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: