python的egg文件有点像java中的jar文件,是一个工程打包文件,便于安装部署,仅此一点,给多少pythoner带来了多少激动。
如何制作egg文件呢?see官方文档http://peak.telecommunity.com/DevCenter/PythonEggs,
到http://pypi.python.org/pypi/setuptools下载setuptools包,然后安装:
python setup.py
1.制作egg文件
下面开始egg文件的制作:(见上一个egg的帖子,比较详细)
在要打包的文件夹父目录中新建setup.py
#setup.py
view plaincopy to clipboardprint?
#coding=utf8
from setuptools import setup, find_packages
setup(
name = "eggtest",
version = "0.1",
packages = find_packages(),
description = "egg test demo",
long_description = "egg test demo",
author = "lidehong",
author_email = "idehong@gmail.com",
license = "GPL",
keywords = ("test", "egg"),
platforms = "Independant",
url = "http://blog.csdn.net/hong201/",
)
#coding=utf8
from setuptools import setup, find_packages
setup(
name = "eggtest",
version = "0.1",
packages = find_packages(),
description = "egg test demo",
long_description = "egg test demo",
author = "lidehong",
author_email = "idehong@gmail.com",
license = "GPL",
keywords = ("test", "egg"),
platforms = "Independant",
url = "http://blog.csdn.net/hong201/",
)
name:包名
version:版本
packages :打包的文件
description:描述信息
author:作者
url:下载地址
执行python setup.py bdist_egg命令之后,在dist目录下会生成egg文件,egg文件其实是一个压缩包,用winzip或者winrar打开就明白了。
试着写了一个NMS plugin的setupegg.py
from setuptools import setup,find_packages
VERSION = "1.0.3"
scripts = ['scripts/zenplugin.py']
setup(name = "NMS-Plugins",
version = VERSION,
description = "NMS-Plugins collect information about the transition information and report them on the command line.",
author = "You Junting",
author_email = "youjt@buptnet.edu.cn",
package_data = {
'' : ['*.txt']
},
license = "GPL",
long_description = "egg test",
keywords= "network management",
url = "http://www.zenoss.com",
packages = ['zenoss', 'zenoss.plugins','parse'],
scripts = scripts
)
利用python setupegg.py -q bdist_egg 命令生成egg文件NMS_Plugins-1.0.3-py2.4.egg
制作安装顺利。
制作其他安装文件:
python setup.py build # 编译
python setup.py sdist # zip格式包
python setup.py bdist_wininst # exe格式包
python setup.py bdist_rpm # rpm格式包
2.egg文件安装(具体见setuptools帖子里的有关叙述)
羡慕cetos的yum,羡慕Ubuntu的apt-get,羡慕ruby的gem,现在python的egg成熟了,强大了,不用再羡慕了。
如果已经把egg文件下载到了本地,则easy_install xxx.egg就ok了,如何有依赖,则会自动下载安装,省心了。如果没有下载下来,网络安装更爽,直接 easy_install 包名,此时喝点咖啡休息一下,回过神来时已经安装好了。唯一一点不好的感觉是,easy_install现在还不支持自动卸载,网上流传的用easy_install -m xxx来卸载,是不行了,这个命令式用来安装同一个包的多个版本的。
3.egg文件卸载
目前不能自动删除egg包,只能手动删除,而手动删除很简单
vim $python_path/Lib/site-packages/easy-install.pth
删除到egg包名所在行,
:wq
重启python环境。
这样做了之后egg包还是遗留下来了,没有被清除,不过这个不用担心,egg包已经不能被引用到python环境了,因为包名中不能有连字符-,而egg文件名中却包含连字符。