什么是Python蛋?

发布于 2024-08-17 18:53:15 字数 94 浏览 8 评论 0原文

我试图了解 Python 包是如何工作的。大概eggs是某种包装机制,但是如何快速概述它们所扮演的角色以及它们为何有用以及如何创建它们的一些信息呢?

I'm trying to understand how Python 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

注意:Egg 包装已被 Wheel 包装取代。

与Java中的.jar文件概念相同,它是一个.zip文件,其中一些元数据文件重命名为.egg,用于分发代码作为捆绑。

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

“Python蛋”是一个逻辑结构,体现了一个
Python 项目的特定版本,包括其代码、资源、
和元数据。有多种格式可用于
对 Python 蛋进行物理编码,并且可以开发其他蛋。然而,
Python Egg 的一个关键原则是它们应该是可发现的并且
可导入的。也就是说,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.

三生路 2024-08-24 18:53:15

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

.egg 文件本身本质上是一个 .zip 文件。如果将扩展名更改为“zip”,您可以看到存档内会有文件夹。

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

示例:
要为 mymath 目录创建 .egg 文件,该目录本身可能有多个 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-信息。我们唯一关心的文件夹是 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

远昼 2024-08-24 18:53:15

免责声明:egg 是一种废弃的 python 包格式,使用 Eggs 的工具已不复存在。

Egg 是一个 python 包。它是一个包含 python 源文件和/或编译库的 zip 存档。

该格式没有明确规定它必须包含什么内容或如何为不同版本的 python 和不同操作系统制作包,这是它被替换的原因之一。

该格式于 2004 年左右出现,一直使用到 2010 年代中期,已完全被 wheelspip install 取代。

Egg 是通过命令 easy_install 安装的。该命令已在 setuptools v58.3(2021 年)中删除。您不能再使用鸡蛋。

如果您看到任何提及 easy_installegg 的内容,无论是任何堆栈溢出答案还是教程,它都已经严重过时了。

推荐这个较长的答案 https://stackoverflow.com/a/68897551/5994461 以深入了解 python 打包的历史。它涉及点、轮子、鸡蛋等等。

更新:截至 2023 年 7 月,官方 python 包存储库 pypi.org 不再接受.egg包上传。

Disclaimer: egg is an abandoned format of python package, the tools to use eggs no longer exist.

An egg is a python package. It's a zip archive containing python source files and/or compiled libraries.

The format is not well specified about what it must contain or how to make packages for different versions of python and different operating systems, that's one of the reasons it was replaced.

The format appeared around 2004 and was in-use until the mid 2010s, it's been completely replaced by wheels and pip install.

Eggs were installed by the command easy_install. The command was removed in setuptools v58.3 (year 2021). You can no longer use eggs.

If you see anything that mentions easy_install or egg, be it any stack overflow answers or tutorials, it is seriously obsolete.

Recommend this longer answer https://stackoverflow.com/a/68897551/5994461 for an in-depth history of python packaging. It's going over pip and wheels and eggs and much more.

Update: As of July 2023 the official python package repository pypi.org no longer accepts upload of .egg packages.

久夏青 2024-08-24 18:53:15

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

“Python Egg 快速指南” 指出“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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文