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文件的制作:
在要打包的文件夹父目录中新建setup.py
#setup.py
view plaincopy to clipboardprint?
01.#coding=utf8
02.
03.from setuptools import setup, find_packages
04.
05.setup(
06. name = "eggtest",
07. version = "0.1",
08. packages = find_packages(),
09.
10. description = "egg test demo",
11. long_description = "egg test demo",
12. author = "lidehong",
13. author_email = "idehong@gmail.com",
14.
15. license = "GPL",
16. keywords = ("test", "egg"),
17. platforms = "Independant",
18. url = "http://blog.csdn.net/hong201/",
19.
20.)
#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文件其实只是一个压缩包。
制作其他安装文件:
python setup.py build # 编译
python setup.py sdist # zip格式包
python setup.py bdist_wininst # exe格式包
python setup.py bdist_rpm # rpm格式包
注: 查看更多命令:
执行 python setup.py --help-commands后可以看到相关可用命令
Standard commands:
build build everything needed to install
build_py "build" pure Python modules (copy to build directory)
build_ext build C/C++ extensions (compile/link to build directory)
build_clib build C/C++ libraries used by Python extensions
build_scripts "build" scripts (copy and fixup #! line)
clean clean up temporary files from 'build' command
install install everything from build directory
install_lib install all Python modules (extensions and pure Python)
install_headers install C/C++ header files
install_scripts install scripts (Python or otherwise)
install_data install data files
sdist create a source distribution (tarball, zip file, etc.)
register register the distribution with the Python package index
bdist create a built (binary) distribution
bdist_dumb create a "dumb" built distribution
bdist_rpm create an RPM distribution
bdist_wininst create an executable installer for MS Windows
upload upload binary package to PyPI
2.egg文件安装
羡慕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文件名中却包含连字符。