将python库/应用程序打包为.egg文件有什么优势?
我已经阅读了一些有关.egg文件的信息,并且在我的lib目录中注意到了它们,但是使用then作为开发人员有什么优点/缺点?
解决方案
回答
来自Python Enterprise Application Kit社区:
"Eggs are to Pythons as Jars are to Java..." Python eggs are a way of bundling additional information with a Python project, that allows the project's dependencies to be checked and satisfied at runtime, as well as allowing projects to provide plugins for other projects. There are several binary formats that embody eggs, but the most common is '.egg' zipfile format, because it's a convenient one for distributing projects. All of the formats support including package-specific data, project-wide metadata, C extensions, and Python code. The primary benefits of Python Eggs are: They enable tools like the "Easy Install" Python package manager .egg files are a "zero installation" format for a Python package; no build or install step is required, just put them on PYTHONPATH or sys.path and use them (may require the runtime installed if C extensions or data files are used) They can include package metadata, such as the other eggs they depend on 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.) 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. 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). There are also other benefits that may come from having a standardized format, similar to the benefits of Java's "jar" format.
-亚当
回答
.egg文件基本上是部署python应用程序的一种好方法。我们可以将其视为Java的.jar文件之类的东西。
更多信息在这里。
回答
鸡蛋是分发python应用程序的一种很好的方法。可以将其视为独立于平台的.deb文件,该文件将安装所有依赖项以及诸如此类的内容。好处是对于最终用户来说很容易使用。缺点是将应用程序打包为.egg文件可能很麻烦。
除了.eggs外,我们还应该提供其他安装方式。有些人不喜欢使用鸡蛋,因为他们不喜欢软件程序安装所需软件的想法。这些通常是sysadmin类型。
回答
无论我们做什么,都不要停止以tarball的形式分发应用程序,因为对于带有软件包sysetem的操作系统而言,这是最容易打包的格式。
回答
对于简单的Python程序,我们可能不需要使用鸡蛋。分发原始的.py文件就足够了;就像分发GNU / Linux的源文件一样。我们还可以使用各种操作系统"打包程序"(例如py2exe或者py2app)为不同的操作系统创建.exe,.dmg或者其他文件。
更复杂的程序,例如Django,由于需要各种模块和依赖项,因此几乎需要鸡蛋。
回答
一个鸡蛋本身并不比适当的源释放更好。好的部分是依赖项处理。就像debian或者rpm软件包一样,我们可以说我们依赖其他鸡蛋,它们会自动安装(通过pypi.python.org)。
第二条评论:egg格式本身是二进制打包格式。仅由python代码组成的普通python软件包最好以"源代码发布"的形式分发,因此" python setup.py sdist"会生成.tar.gz。当上传到pypi时,这些通常也称为"鸡蛋"。
需要二进制鸡蛋的地方:捆绑某些C代码扩展时。然后,我们将需要几个二进制鸡蛋(一个32位的Unix鸡蛋,一个Windows的鸡蛋等等)。