http://peak.telecommunity.com/DevCenter/PythonEggs
概览
Eggs 之于 python,就像jar 之于Java
python eggs 将python工程和相关的信息进行打包,有一些二进制格式代表eggs
,更常见的是.egg
压缩格式.所有的格式都支持包含package-specific data, project-wide metadata, C extensions, and Python code.
最简单安装egg
的方法是使用Easy Install
.可以通过setuptools
来创建egg.
egg的优点有:
1.通过easy install
来安装
2..egg
文件是0安装格式,只要把他们放在PYTHONPATH
或者sys.path
中即可
3.可以包含包信息,比如其他的依赖
4.They allow “namespace packages” (packages that just contain other packages) to be split into separate distributions (e.g. zope., twisted., peak.* packages can be distributed as separate eggs, unlike normal packages which must always be placed under the same parent directory. This allows what are now huge monolithic packages to be distributed as separate components.)
5.They allow applications or libraries to specify the needed version of a library, so that you can e.g. require(“Twisted-Internet>=2.0”) before doing an import twisted.internet.
6.They’re a great format for distributing extensions or plugins to extensible applications and frameworks (such as Trac, which uses eggs for plugins as of 0.9b1), because the egg runtime provides simple APIs to locate eggs and find their advertised entry points (similar to Eclipse’s “extension point” concept).
使用Eggs
Automatic Discovery
Building Eggs
Declaring Dependencies
Developing with Eggs
Running Eggs from Source
Accessing Package Resources
使用__file__
和__path__
来定位包的路径,比如一个模块需要读取foo.config
:
foo_config = open(os.path.join(os.path.dirname(__file__),'foo.conf').read()