什么是Python鸡蛋?

问题:什么是Python鸡蛋?

我是Python的新手,只是想了解它的软件包是如何工作的。大概“蛋”是某种包装机制,但是如何快速概述它们所扮演的角色,以及可能提供有关为什么它们有用以及如何创建它们的一些信息?

I’m new to Python and am just trying to understand how its packages work. Presumably “eggs” are some sort of packaging mechanism, but what would be a quick overview of what role they play and may be some information on why they’re useful and how to create them?


回答 0

注意:鸡蛋包装已被滚轮包装取代。

.jarJava文件的概念相同,它是.zip重命名了一些元数据文件的文件.egg,用于将代码作为分发包分发。

具体来说:Python Eggs的内部结构

“ Python鸡蛋”是一种逻辑结构,体现了特定版本的Python项目的发布,包括其代码,资源和元数据。可以使用多种格式对Python鸡蛋进行物理编码,还可以开发其他格式。但是,Python鸡蛋的关键原则是它们应该是可发现的和可导入的。也就是说,Python应用程序应该有可能轻松有效地找出系统中存在的卵,并确保所需卵的内容可导入。

.egg格式非常适合于分发以及代码的轻松卸载或升级,因为该项目本质上是独立的,包含在单个目录或文件中,没有与任何其他项目的代码或资源混合在一起。它还可以同时安装一个项目的多个版本,以便各个程序可以选择他们想要使用的版本。

Note: Egg packaging has been superseded by Wheel packaging.

Same concept as a .jar file in Java, it is a .zip file with some metadata files renamed .egg, for distributing code as bundles.

Specifically: The Internal Structure of Python Eggs

A “Python egg” is a logical structure embodying the release of a specific version of a Python project, comprising its code, resources, and metadata. There are multiple formats that can be used to physically encode a Python egg, and others can be developed. However, a key principle of Python eggs is that they should be discoverable and importable. That is, it should be possible for a Python application to easily and efficiently find out what eggs are present on a system, and to ensure that the desired eggs’ contents are importable.

The .egg format is well-suited to distribution and the easy uninstallation or upgrades of code, since the project is essentially self-contained within a single directory or file, unmingled with any other projects’ code or resources. It also makes it possible to have multiple versions of a project simultaneously installed, such that individual programs can select the versions they wish to use.


回答 1

.egg文件是Python软件包的分发格式。它只是源代码发行版或Windows的替代方案exe。但是请注意,对于pure Python.egg文件是完全跨平台的。

.egg文件本身实质上是一个.zip文件。如果将扩展名更改为“ zip”,则可以看到它在存档中将包含文件夹。

另外,如果您有.egg文件,则可以使用以下文件作为软件包安装easy_install

示例:要.egg为目录创建一个文件,例如mymath它本身可能具有多个python脚本,请执行以下步骤:

# setup.py
from setuptools import setup, find_packages
setup(
    name = "mymath",
    version = "0.1",
    packages = find_packages()
    )

然后,从终端执行:

 $ python setup.py bdist_egg

这将产生很多输出,但是完成后,您会看到拥有三个新文件夹:builddistmymath.egg-info。我们唯一关心的文件夹是dist文件夹,您可以在其中找到.egg文件,mymath-0.1-py3.5.egg带有默认的python(安装)版本号(此处为3.5)

资料来源:Python库博客

The .egg file is a distribution format for Python packages. It’s just an alternative to a source code distribution or Windows exe. But note that for pure Python, the .egg file is completely cross-platform.

The .egg file itself is essentially a .zip file. If you change the extension to “zip”, you can see that it will have folders inside the archive.

Also, if you have an .egg file, you can install it as a package using easy_install

Example: To create an .egg file for a directory say mymath which itself may have several python scripts, do the following step:

# setup.py
from setuptools import setup, find_packages
setup(
    name = "mymath",
    version = "0.1",
    packages = find_packages()
    )

Then, from the terminal do:

 $ python setup.py bdist_egg

This will generate lot of outputs, but when it’s completed you’ll see that you have three new folders: build, dist, and mymath.egg-info. The only folder that we care about is the dist folder where you’ll find your .egg file, mymath-0.1-py3.5.egg with your default python (installation) version number(mine here: 3.5)

Source: Python library blog


回答 2

Python蛋是将附加信息与Python项目捆绑在一起的一种方式,它允许在运行时检查和满足项目的依赖关系,并允许项目为其他项目提供插件。有几种包含鸡蛋的二进制格式,但是最常见的是’.egg’zipfile格式,因为它是分发项目的便捷方式。所有格式都支持,包括特定于软件包的数据,项目范围的元数据,C扩展名和Python代码。

安装和使用Python egg的最简单方法是使用“简易安装” Python软件包管理器,它将为您查找,下载,构建和安装egg。您要做的就是告诉它您要使用的Python项目的名称(以及版本)。

Python鸡蛋可以与Python 2.3及更高版本一起使用,并且可以使用setuptools软件包进行构建(有关源代码,请参见Python Subversion沙箱;有关当前安装说明,请参见EasyInstall页面)。

Python Eggs的主要好处是:

  • 它们启用了诸如“轻松安装” Python软件包管理器之类的工具

  • .egg文件是Python软件包的“零安装”格式;无需构建或安装步骤,只需将它们放在PYTHONPATH或sys.path上并使用它们即可(如果使用C扩展名或数据文件,则可能需要安装运行时)

  • 它们可以包括包元数据,例如它们依赖的其他鸡蛋

  • 它们允许将“命名空间包”(仅包含其他包的包)拆分为单独的分布(例如zope。,twisted。,peak。*)包可以作为单独的鸡蛋分发,这与通常必须始终放在同一包下的普通包不同父目录。这允许将现在庞大的整体软件包作为单独的组件分发。)

  • 它们允许应用程序或库指定库的所需版本,以便您可以在导入twisted.internet之前例如require(“ Twisted-Internet> = 2.0”)。

  • 对于将扩展或插件分发到可扩展的应用程序和框架,它们是一种很好的格式(例如Trac,它从0.9b1开始使用鸡蛋作为插件),因为Egg运行时提供了简单的API来查找鸡蛋并找到其广告入口点(类似Eclipse的“扩展点”概念)。

标准化格式还会带来其他好处,类似于Java的“ jar”格式的好处。

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 easiest way to install and use Python eggs is to use the “Easy Install” Python package manager, which will find, download, build, and install eggs for you; all you do is tell it the name (and optionally, version) of the Python project(s) you want to use.

Python eggs can be used with Python 2.3 and up, and can be built using the setuptools package (see the Python Subversion sandbox for source code, or the EasyInstall page for current installation instructions).

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.


回答 3

“ Egg”是与Python相关的项目的单文件可导入分发格式。

“ Python Eggs快速指南”指出:“ Eggs是Python,而Jars是Java …”

鸡蛋实际上比罐子还要丰富。它们包含有趣的元数据,例如许可详细信息,发布依赖项等。

“Egg” is a single-file importable distribution format for Python-related projects.

“The Quick Guide to Python Eggs” notes that “Eggs are to Pythons as Jars are to Java…”

Eggs actually are richer than jars; they hold interesting metadata such as licensing details, release dependencies, etc.